I have a List<T> object. It has a children from the same type (Tree[].Tree[].Tree[]...). How can i use this structure, to show as a tree?
This is my class and list from it:
class Tree{
public string Name { get; set; }List<Tree> children;
}
xamDataTree.ItemsSource = List<Tree> object
Where is my error? I can see only the root level of the tree.
Hi Synthy,
I suppose that in your XAML you missed definition of 'NodeLayout'.In XAML your tree shoud be:
<ig:XamDataTree x:Name="dataGlobalTree" ItemsSource="{Binding Object}" > <ig:XamDataTree.GlobalNodeLayouts> <ig:NodeLayout Key="Data" DisplayMemberPath="Name" TargetTypeName="Tree"></ig:NodeLayout> </ig:XamDataTree.GlobalNodeLayouts></ig:XamDataTree>
Hi Tanya,thank you about your answer. I did make what you said, but i still can see only the root element. This is my code, now a concrete example:
the C# code about helper class:
public class navigatorTree { public ACIDServices.NavigatorRole element { get; set; } public List<navigatorTree> children;
public static List<navigatorTree> getNavigatorTree(List<ACIDServices.NavigatorRole> tree) { List<navigatorTree> result = new List<navigatorTree>(); navigatorTree tempElement = new navigatorTree(); List<ACIDServices.NavigatorRole> tempResult = tree.FindAll(delegate(ACIDServices.NavigatorRole p) { return p.HID == 0; }); foreach (ACIDServices.NavigatorRole navRole in tempResult) { tempElement = new navigatorTree(); tempElement.element = navRole; tempElement.children = getSubNavigatorTree(navRole, tree); result.Add(tempElement); } return result; }
The code, which i use to databind the xamDataTree:
List<ACIDServices.NavigatorRole> navigatorRole = new List<ACIDServices.NavigatorRole>(); asc.GetNavigator(out navigatorRole, SESSION.Session.Get("SessionID").ToString(), (int)SESSION.Session.Get("ofpRoleID"), true); Resources.Add("navigatorTree", ACID_WPF_FE.AppGlobalCode.treeHelper.getNavigatorTree(navigatorRole));
// Now i have a hierarchical List from navigatorTree. The property "children" has more items from navigatorTree, which has another children with list of navigatorTree...
and the XAML:
<ig:XamDataTree HorizontalAlignment="Left" Name="xamDataTree1" VerticalAlignment="Top" ItemsSource="{DynamicResource navigatorTree}" Width="125"> <ig:XamDataTree.GlobalNodeLayouts> <ig:NodeLayout Key="element" TargetTypeName="ACID_WPF_FE.AppGlobalCode.navigatorTree" DisplayMemberPath="element.NAME" /> </ig:XamDataTree.GlobalNodeLayouts> </ig:XamDataTree>
and after F5, i can see only the first level from datasource (List<navigatorTree>) :(
In the Example browser, i saw that the itemsSource is in XML. Is it the key from the house?