Wednesday, 28 August 2013

wpf mvvm recursive tree

wpf mvvm recursive tree

i have two classes
public class leaf
{
public string name { get; set; }
}
and
public class node
{
public ObservableCollection<node> nodeList = new
ObservableCollection<node>();
public ObservableCollection<leaf> leafList = new
ObservableCollection<leaf>();
public ObservableCollection<node> prop_nodeList { get { return
nodeList; } set { nodeList = value; } }
public ObservableCollection<leaf> prop_leafList { get { return
leafList; } set { leafList = value; } }
public string name { get; set; }
}
as you can see its work like roads or tree. node can have information on
another node and leaf.
i would like to show in user control tree formated like that

nethead is a main node, and its have two another node (b, a). node a have
two node(b,c) and 2 leaf (a1, a2). but i dont do it with mvvm. when i do
it with mvvm its look like

from C# im doing only
this.DataContext = mainNode; // its node which hold everething (its named
netHead)
from xaml its
<Grid>
<TreeView ItemsSource="{Binding prop_nodeList}">
<TreeView.Resources>
<HierarchicalDataTemplate DataType="{x:Type local:node}"
ItemsSource="{Binding prop_nodeList}">
<TextBlock Text="{Binding Path=name}"/>
</HierarchicalDataTemplate>
<HierarchicalDataTemplate DataType="{x:Type local:leaf}"
ItemsSource="{Binding prop_leafList}">
<TextBlock Text="{Binding Path=name}"/>
</HierarchicalDataTemplate>
</TreeView.Resources>
</TreeView>
</Grid>
you see what i want to do ? i want to make double treeItem in TreeView,
but it doesnt work :( please help, its projekt for Ant Algorithm and i
want to do the best gui in class room

No comments:

Post a Comment