HierarchicalDataTemplate - Edit item template

2 posts, 1 answers
  1. Justin Lee
    Justin Lee avatar
    140 posts
    Member since:
    Dec 2009

    Posted 25 Feb 2013 Link to this post

    I have a collection of categories, and each category contains a list of items.  I'm binding it to a RadTreeView and want the tree to be editable by the user.  I successfully bound the collection to the tree, however I'm I can't figure out how to have one data template for the editing of category, and another for editing of an item (child).  (the hierarchy is only 2 deep)

    How can I have separate data templates for Editing?

    <UserControl.Resources>
          <DataTemplate x:Key="ChildItemTemplate">
             <TextBlock Text="{Binding ItemName, Mode=TwoWay}" FontSize="9" Width="130" />
         </DataTemplate>
         <DataTemplate x:Key="CategoryEditTemplate">
             <TextBox Text="{Binding CategoryName, Mode=TwoWay}" FontSize="9" Width="130" />
         </DataTemplate>
         <telerik:HierarchicalDataTemplate x:Key="TreeDataTemplate" ItemsSource="{Binding ChildItems}"
                              ItemTemplate="{StaticResource ChildItemTemplate}">
             <TextBlock Text="{Binding CategoryName}" FontSize="9" />
         </telerik:HierarchicalDataTemplate>
     </UserControl.Resources>
     
     <telerik:RadTreeView ItemsSource="{Binding Categories}"
                  ItemTemplate="{StaticResource TreeDataTemplate}"
                  ItemEditTemplate="{StaticResource CategoryEditTemplate}"  />

  2. Answer
    Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    907 posts
    Member since:
    May 2013

    Posted 28 Feb 2013 Link to this post

    Hi Justin,

    In order to set different DataTemplates when you go in edit mode you can use the ItemEditTemplateSelector property of the RadTreeView control. Please keep in mind that when using this property you have to set the ItemEditTemplate property of the control to Null. For more information you can refer to this article. In the attached project I created an EditTemplateSelector class deriving from DataTemplateSelector and I overrode the SelectTemplate() method. Please take a look at the attached project and let me know if it works for you.

    Regards,
    Pavel R. Pavlov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. Download a free trial of UI for WPF
Back to Top