Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
610
Best way to create tree by 'Group' string property
posted

Hi,

Lets say I have Collection of items with

public String Group { set; get; }
for each item.

What would be the best way to bind this collection to TreeView while each item will be under his group, and the groups will be like folders?

For example:  

Data = [ {Item1,GroupA} , {Item2,GroupA} , {Item3,GroupB} ]

Tree:

   > GroupA

      > Item1

      > Item2

   > GroupB

      > Item3


Thanks! :D

  • 6759
    Offline posted

    Hi guypld,

    I don't think there is a feasible way to feed this collection to the XamDataTree and get the desired layout. So you'll have to transform this collection to be a bit more Data Tree friendly. Something like the following:

    public class Group
    {
            public string GroupName { get; set; }
            public IEnumerable<Item> {get; set;}
    }

    public class Item
    {
        public string ItemName { get; set; }
    }

    Then you would have to define two NodeLayouts. For example:

    <ig:NodeLayout Key="someKeyHere"   
            TargetTypeName="Group" 
            DisplayMemberPath="GroupName">
    </ig:NodeLayout>

    <ig:NodeLayout Key="Children"   
            TargetTypeName="Item" 
            DisplayMemberPath="ItemName">
    </ig:NodeLayout>

    Here is an article describing in detail how the node layouts are functioning and how to configure them to achieve the desired outcome.

    Let me know if I could be of further help with this matter.