DragCue Template in Hierarchical TreeView Drag & Drop

5 posts, 1 answers
  1. Dan
    Dan avatar
    5 posts
    Member since:
    Jun 2009

    Posted 13 Jan 2010 Link to this post

    I'm using a RadTreeView with multiple levels of HierarchicalDataTemplates, when I try and drag an item from a lower level it always uses the DataTemplate for the top level.  Only way I can see to fix it right now is to implement the TreeView drag drop myself, which I'd rather avoid.

    I quickly modified a sample found at  http://www.telerik.com/ClientsFiles/163825_testtreeview1.zip
    The tree looks correct but when I drag a child I don't see the 'blah' that prepended it in the tree because it is using the root template.
    I've tried hooking the DragQuery and setting the e.Options.DragCue but that did not seem to change anything.

    <UserControl x:Class="TestTreeView1.MainPage" 
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
        xmlns:telerikNavigation="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation" 
        xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls" 
        mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480"
        <UserControl.Resources> 
            <telerik:HierarchicalDataTemplate x:Key="childTemplate" 
                                              ItemsSource="{Binding SearchDef.SearchItems, Mode=OneWay}" 
                                                      > 
                <StackPanel Orientation="Horizontal"
                    <TextBlock Text="blah"  /> 
                    <TextBlock Text="{Binding Name}" FontWeight="Bold" FontSize="12" /> 
                </StackPanel> 
            </telerik:HierarchicalDataTemplate> 
        </UserControl.Resources> 
      <Grid x:Name="LayoutRoot"
     
     
     
            <telerikNavigation:RadTreeView x:Name="RadTreeView1"  
                        Margin="10" 
                        IsLineEnabled="True" SelectionMode="Single" IsEditable="True" 
                        IsDragDropEnabled="True" 
                        PreviewDragStarted="RadTreeView1_PreviewDragStarted" 
                        IsDragTooltipEnabled="True" 
                        ItemsSource="{Binding SearchDef.SearchItems, Mode=OneWay}" 
                                           > 
                <telerikNavigation:RadTreeView.ItemTemplate> 
                    <telerik:HierarchicalDataTemplate ItemsSource="{Binding SearchDef.SearchItems, Mode=OneWay}" 
                                                      ItemTemplate="{StaticResource childTemplate}"
                        <StackPanel Orientation="Horizontal"
                            <TextBlock Text="{Binding Name}" FontWeight="Bold" FontSize="12" /> 
                        </StackPanel> 
                    </telerik:HierarchicalDataTemplate> 
                </telerikNavigation:RadTreeView.ItemTemplate> 
            </telerikNavigation:RadTreeView> 
           
        </Grid> 
    </UserControl> 
     

  2. Miroslav
    Admin
    Miroslav avatar
    922 posts

    Posted 15 Jan 2010 Link to this post

    Hello Dan,

    Yes, the chosen template does not "stick" with an item. When you define the second level template to be something, then it will be this template for all second level items regardless of whether they were  dragged from level 1.

    You have total control over the templates with the ItemTemplate selector. There you can choose the template for an item based on custom logic which may not be level-based. This help article is on the DataTemplateSelectors:

    http://www.telerik.com/help/silverlight/radtreeview-templating-item-template-selector.html

    Hopefully this will work for you.

    Regards,
    Miroslav
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Dan
    Dan avatar
    5 posts
    Member since:
    Jun 2009

    Posted 21 Jan 2010 Link to this post

    Hey Miroslav, was just sitting down to implement your suggestion and I just wanted to be clear on the point you were making about the templates.

    When you define the second level template to be something, then it will be this template for all second level items regardless of whether they were  dragged from level 1.

    My problem doesn't really have anything to do with item templates, and I wasn't really clear about this.  I'm fine with what you suggested, that a top level item will always have a top level item template even if I drag it down a level.  However I'm talking about a drag overlay template for an item that is a child item and has always been a child.  So this item has ItemTemplate={StaticResource childTemplate}  but the overlay being shown when I drag is parentTemplate.

    So
    A
     - B
     - B
    A
     - B
     - B

    If that is my tree right after construction, if I drag an A, the overlay looks great, however if I drag a B the overlay makes it look like an A

  4. Answer
    Miroslav
    Admin
    Miroslav avatar
    922 posts

    Posted 25 Jan 2010 Link to this post

    Hi Dan,

    Thank you for the clarification! You do bring up the valid point and I reproduced what you described.

    Ineed the TreeViewDragCue uses the ItemTemplate and ItemTemplateSelector of the TreeView. It is a non-hierarchical items control and it flattens the hierarchy of the TreeView (i.e. all dragged items will appear as first-level items in the DragCue). This is a simplification in the DragDrop logic that appears as a bug in this case.

    Currently the workaround is to use an ItemTemplateSelector which will be correctly used by the DragCue.

    The issue has been logged.

    Your Telerik Points have been updated for your feedback.

    Sincerely yours,
    Miroslav
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  5. Dan
    Dan avatar
    5 posts
    Member since:
    Jun 2009

    Posted 11 Feb 2010 Link to this post

    Worked perfectly, thanks Miroslav.
Back to Top