Hi,
I have a list of categories, items and sub-categories in my data model.
My ViewModel contains a list of Items which can be nodes or sub-nodes etc:
public List<Item> Data { get; set; }
The Category class is derived from the item class:
public class Category : Item { public List<Item> Items { get; set; } }
public class Item { public string Label { get; set; } }
The XamDataTree does not display all levels of the tree and stops at the first sub-level
The tree should be:
Item 1
Item 2
Item 3
Cat1
Item 4
Item 5
Item 6
Item 7
Cat2
Item 8
Item 9
Sub Cat3
Item 10
Item 11
But "Sub Cat3" does not have an expansion indicator and Item10 and Item 11 are not shown.
XamDataTreeItemsDemo2.zip
Is there a way of making the tree recursive and show all nodes, sub-nodes etc, etc?
Regards,
Tony
Hello Tony,
This is expected ,you are adding items with their own subset of items. The tree will want to show the root node in each child.
You can have a look at this thread to solve the issue.
https://www.infragistics.com/community/forums/f/ultimate-ui-for-wpf/120191/displaying-three-types-in-a-xamdatatree-on-both-parent-and-child-levels
Let me know if you have a question.
Hi Divya,
Thank you for your response. I have tried creating the nodes programmatically as mentioned in the attached thread but this does not seem to work using the attached code:
private void XamDataTree_InitializeNode(object sender, Infragistics.Controls.Menus.InitializeNodeEventArgs e) { Category cat = e.Node.Data as Category;
if (cat != null && cat.Items.Any() && !e.Node.HasChildren) { var index = 0; foreach (var item in cat.Items) { e.Node.Nodes.Add(new Infragistics.Controls.Menus.XamDataTreeNode(index++, e.Node.Manager,item, false, e.Node.NodeLayout)); } } }
I find your xaml need to modify like this,which will fix your issue:
<ig:XamDataTree ItemsSource="{Binding Data}" DisplayMemberPath="Label"> <ig:XamDataTree.GlobalNodeLayouts> <ig:NodeLayout Key="Data" TargetTypeName="Item" DisplayMemberPath="Label"> <ig:NodeLayout.NodeLayouts> <ig:NodeLayout Key="Items" TargetTypeName="Item" DisplayMemberPath="Label"/> </ig:NodeLayout.NodeLayouts> </ig:NodeLayout> </ig:XamDataTree.GlobalNodeLayouts> </ig:XamDataTree>
Let me know if you have any question.