This is a migrated thread and some comments may be shown as answers.

Drag & Drop Display Issue With Hierarchical Data Templates

2 Answers 52 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Geoff Davis
Top achievements
Rank 1
Geoff Davis asked on 02 Apr 2010, 05:53 PM
Hi,

I'm working with a two-level treeview and am able to drag elements from the first level without any complications.  When I drag from the second level, however, the dragged item displays using the template for the first level.

These are the two templates being used:
<core:HierarchicalDataTemplate x:Key="SectionsTemplate"
                <Border BorderThickness="1,0,1,0" CornerRadius="4" BorderBrush="Red"  
                        Background="{Binding Index, Converter={StaticResource AlternateBrush}}" 
                        MouseEnter="SectTemplate_MouseEnter" 
                        MouseLeave="SectTemplate_MouseLeave" 
                        > 
                    <Grid Margin="2" Loaded="SectionsTemplate_Loaded"
                        <Grid.ColumnDefinitions> 
                            <ColumnDefinition Width="5" /> 
                            <ColumnDefinition Width="50" /> 
                            <ColumnDefinition Width="90" /> 
                            <ColumnDefinition Width="108" /> 
                            <ColumnDefinition Width="5" /> 
                        </Grid.ColumnDefinitions> 
                        <Grid.RowDefinitions> 
                            <RowDefinition /> 
                            <RowDefinition Height="2" /> 
                            <RowDefinition /> 
                        </Grid.RowDefinitions> 
                         
                        <!--1st Column--> 
                        <TextBlock Grid.Column="1" Grid.Row="0" 
                                   Text="{Binding SectionNumber}" /> 
 
                        <TextBlock Grid.Column="1" Grid.Row="2" 
                                   Text="{Binding Days}" />                                                                        
 
                        <!--2nd Column--> 
                        <TextBlock Grid.Column="2" Grid.Row="0" 
                                   Text="{Binding CallNumber}" /> 
                         
                        <TextBlock Grid.Column="2" Grid.Row="2" 
                                   Text="{Binding TimeSlot}" /> 
                                                                                               
                        <!--3rd Column--> 
                        <TextBlock Grid.Column="3" Grid.Row="0" 
                                   Text="{Binding Instructor}" /> 
 
                        <TextBlock Grid.Column="3" Grid.Row="2" 
                                   Text="{Binding Location}" /> 
 
                    </Grid> 
                </Border>               
            </core:HierarchicalDataTemplate> 
             
            <core:HierarchicalDataTemplate x:Key="CoursesTemplate" 
                                           ItemsSource="{Binding Sections}" 
                                           ItemTemplate="{StaticResource SectionsTemplate}" 
                                           > 
                <Border CornerRadius="5" BorderBrush="Maroon" BorderThickness="1"  
                        MouseEnter="CourseTemplate_MouseEnter" 
                        MouseLeave="CourseTemplate_MouseLeave" 
                        >                    
                    <Border.Background> 
                        <LinearGradientBrush EndPoint="0.5,1" 
                                             StartPoint="0.5,-0.142"
                            <GradientStop Color="#7F420000" 
                         Offset="0.92" /> 
                            <GradientStop Color="White" 
                         Offset="0.007" /> 
                            <GradientStop Color="#FF943D3D" 
                         Offset="0.374" /> 
                            <GradientStop Color="#FEB58787" 
                         Offset="0.678" /> 
                            <GradientStop Color="#FF630000" /> 
                        </LinearGradientBrush> 
                    </Border.Background> 
                     
                    <Grid Margin="2"  Loaded="CoursesTemplate_Loaded"
                        <Grid.Background> 
                            <LinearGradientBrush EndPoint="0.5,1" 
                                                 StartPoint="0.5,0"
                                <GradientStop Color="#FF922222" 
                          Offset="1" /> 
                                <GradientStop Color="#FFF1DDDD" /> 
                                <GradientStop Color="#FFB54242" 
                          Offset="0.478" /> 
                                <GradientStop Color="#FBB58787" 
                          Offset="0.418" /> 
                            </LinearGradientBrush> 
                        </Grid.Background> 
                        <Grid.ColumnDefinitions> 
                            <ColumnDefinition Width="4" /> 
                            <ColumnDefinition Width="70" />                         
                            <ColumnDefinition Width="30" /> 
                            <ColumnDefinition Width="180" />                             
                        </Grid.ColumnDefinitions>                                                
                         
                        <StackPanel Grid.Column="1" Orientation="Horizontal">                         
                            <TextBlock Foreground="White"  Text="{Binding DiscCode}" /> 
                            <TextBlock Foreground="White"  Text="{Binding Number}" />                         
                        </StackPanel> 
                         
                        <TextBlock Foreground="White"  Grid.Column="2" Text="{Binding Credits}" /> 
                         
                        <TextBlock Foreground="White"  Grid.Column="3" Text="{Binding Name}" /> 
                     
                    </Grid> 
                     
                </Border> 
            </core:HierarchicalDataTemplate> 

And this is the treeview definition:
<nav:RadTreeView x:Name="CoursesTree" 
                             Grid.Row="4" 
                             Grid.ColumnSpan="2" 
                             IsTriStateMode="True" 
                             ItemsOptionListType="CheckList" 
                             IsOptionElementsEnabled="True" 
                             SelectionMode="Extended" 
                             ItemsSource="{Binding Courses}" 
                             ItemTemplate="{StaticResource CoursesTemplate}" 
                             HorizontalAlignment="Left" 
                             Checked="CoursesTree_Checked" 
                             Unchecked="CoursesTree_Checked" 
                             ItemPrepared="CoursesTree_ItemPrepared" 
                             IsDragDropEnabled="True" 
                             /> 


I assume this is not an inherent problem in the control, but don't see what in these declarations would cause the issue.  The version of the control being used is 2009.3.1208.1030

Any light that could be shed on this would be greatly appreciated.


Thanks,
Geoff

2 Answers, 1 is accepted

Sort by
0
Accepted
Tina Stancheva
Telerik team
answered on 07 Apr 2010, 06:55 PM
Hi Geoff Davis,

After examining the code snippet you provided I noticed that you set the ItemTemplate property of the RadTreeView. This is the cause for the behavior you noticed. The DagPreview uses the template set as ItemTemplate when displaying the dragged item. If you want to use different templates for the dragged items depending on their type, it is better to set the ItemTemplateSelector property of the RadTreeView.

I prepared an example for you. Please take a look at it and let me know if it works for you.

Kind regards,
Tina Stancheva
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Geoff Davis
Top achievements
Rank 1
answered on 08 Apr 2010, 12:18 AM
Awesome - thanks for that.


Geoff
Tags
TreeView
Asked by
Geoff Davis
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Geoff Davis
Top achievements
Rank 1
Share this question
or