HierarchicalDataTemplate question

2 posts, 0 answers
  1. sharp
    sharp avatar
    27 posts
    Member since:
    Feb 2011

    Posted 13 Feb 2012 Link to this post

    Hi. I have class
    public class Tree
    {
    public string Name {get;set;}
    public ObservableCollection<MyClass1> Folder1{get;set;}
    public ObservableCollection<MyClass2> Folder1{get;set;}
    public ObservableCollection<MyClass3> Folder1{get;set;}
    }
     
    public class MyClass1
    {
    public string Name;
    public ObservableCollection<MyClass4> someData
    }
    public class MyClass2
    {
    public string Name;
    public ObservableCollection<MyClass5> someData
    }
    public class MyClass3
    {
    public string Name;
    public ObservableCollection<MyClass6> someData
    }

    And I want create tree that look like

    TreeName
           |
           MyClass1Element
                         |
                          MyClass4Element
           |
            MyClass2Element
                          |
                            MyClass5Element
           |
            MyClass3Element
                            |
                             MyClass6Element


    Please tell me what I must do for this tree?

  2. Hristo
    Admin
    Hristo avatar
    352 posts

    Posted 15 Feb 2012 Link to this post

    Hi,

    You could take a look at the following article as a start: http://www.telerik.com/help/silverlight/radtreeview-populating-with-data-hierarchical-data-templates.html 

    You could use ItemTemplate property of the HierarchicalDataTemplate element to provide data template (or hierarchical template) for the children of the element.

    <DataTemplate x:Key="ThirdLevelTemplate">
        <TextBlock Text="{Binding Name}" />
    </DataTemplate>
     
    <telerik:HierarchicalDataTemplate x:Key="SecondLevelTemplate"
            ItemsSource="{Binding Items}"
            ItemTemplate="{StaticResource ThirdLevelTemplate}">
        <TextBlock Text="{Binding Name}" />
    </telerik:HierarchicalDataTemplate>
     
    <telerik:HierarchicalDataTemplate x:Key="FirstLevelTemplate"
            ItemsSource="{Binding Items}"
            ItemTemplate="{StaticResource SecondLevelTemplate}">
        <TextBlock Text="{Binding Name}" />
    </telerik:HierarchicalDataTemplate>

    You could also take a look at our online demos for inside and samples: http://demos.telerik.com/silverlight/#TreeView/FirstLook.

    Hope this helps, please let us know if you need further assistance.
    Regards,
    Hristo
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  3. DevCraft banner
Back to Top