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

Bind tree to recursive hierarchical data

1 Answer 184 Views
TreeListView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Andrej
Top achievements
Rank 1
Andrej asked on 22 May 2012, 08:22 AM
Hi
I have a class representing a node in a tree:

public class NavigationItem
{
    public string Title { get; set; }
    public string Icon { get; set; }
    public string SomeUrl { get; set; }

    public ObservableCollection<NavigationItem> Items { get; set; }
}

How do you create a HierarchicalDataTemplate so that it generates a recursive tree. Bellow is the sample data:

public class NavigationItemCollection
{
    public ObservableCollection<NavigationItem> Items;
     
    public NavigationItemCollection()
    {
        Items = new ObservableCollection<NavigationItem>();
         
        Items.Add(new NavigationItem() {
            Title = "Node 1",
            Icon = "Icon1.png",
            SomeUrl = "/test1",
            Items = new ObservableCollection<NavigationItem>(){
                new NavigationItem() { Title = "SubNode 1", Icon = "SubIcon1.png", SomeUrl = "/subtest1" },
                new NavigationItem() { Title = "SubNode 2", Icon = "SubIcon2.png", SomeUrl = "/subtest1" }
            }
        });
        Items.Add(new NavigationItem() { Title = "Node 2", Icon = "Icon2.png", SomeUrl = "/test2" });
        Items.Add(new NavigationItem() { Title = "Node 3", Icon = "Icon3.png", SomeUrl = "/test3" });
    }
}

Thanks for your help!

1 Answer, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 22 May 2012, 08:57 AM
Hi,

 Have you checked our online demo?

Regards,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
TreeListView
Asked by
Andrej
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Share this question
or