HierarchicalDataTemplate - Unlimited

3 posts, 0 answers
  1. Marinko
    Marinko avatar
    4 posts
    Member since:
    Sep 2010

    Posted 14 Dec 2010 Link to this post

    public class Node
    {
      public Node(string myText)
      {
         this.Text = myText;
         this.Nodes = new ObservableCollection<Node>();
      }
      
      public string Text { get; set; }
      
      public ObservableCollection<Node> Nodes { get; private set; }
    }

    ObservableCollection<Node> nodes = new ObservableCollection<Node>(); 
                      
    nodes.Add(new Node("Company"));
    nodes[0].Nodes.Add(new Node("Department"));
    nodes[0].Nodes[0].Nodes.Add(new Node("here are you"));
      
    radTreeView1.ItemsSource = nodes;

    <Window.Resources>
        <DataTemplate x:Key="itemTemplate">
            <TextBlock x:Name="child" Text="{Binding Text}"/>
        </DataTemplate>
        <HierarchicalDataTemplate x:Key="masterTemplate" ItemsSource="{Binding Nodes}" ItemTemplate="{StaticResource itemTemplate}">
            <telerik:RadTreeViewItem Header="{Binding Text}"/>
        </HierarchicalDataTemplate>
    </Window.Resources>
    <Grid>
        <telerik:RadTreeView Name="radTreeView1" ItemTemplate="{StaticResource masterTemplate}"/>
    </Grid>

    Why "here are you" is not displayed? This is the idea of HierarchicalDataTemplate or not?

    Kind regards,

    Marinko
  2. Vladislav
    Admin
    Vladislav avatar
    275 posts

    Posted 17 Dec 2010 Link to this post

    Hello Marinko,

    The "here are you" node is not displayed, because of the Hierarchical's ItemTemplate.
    If you remove it, you are able to create nested RadTreeViewItems as more as you wish.
    The reason for this is that you are setting the ItemTempalte to have only one nested RadTreeViewItem.

    You can check the attached project for demonstration of styling the same way all the RadTreeViewItems.
    The main purpose for using HierarchicalDataTemplate is to apply different style for the different levels of the RadTreeView, but you should provide additional HierarchicalDataTemplate for every nested level.

    You can also check this help article.

    Kind regards,
    Vladislav
    the Telerik team
    Browse the videos here>> to help you get started with RadControls for WPF
  3. UI for WPF is Visual Studio 2017 Ready
  4. Marinko
    Marinko avatar
    4 posts
    Member since:
    Sep 2010

    Posted 17 Dec 2010 Link to this post

    <HierarchicalDataTemplate x:Key="rufTreeNode" ItemsSource="{Binding Rows}">
        <TextBlock Text="{Binding Caption}"/>
    </HierarchicalDataTemplate>

    Using just the xaml above solved my problem.

    Thanks
    Marinko
Back to Top