Bind tree to recursive hierarchical data

2 posts, 0 answers
  1. Reggie
    Reggie avatar
    3 posts
    Member since:
    May 2012

    Posted 22 May 2012 Link to this post

    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!
  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 22 May 2012 Link to this post

    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 >>

  3. DevCraft banner
Back to Top