Dictionary in <string, Custometype>custometype is a collection that binds it to a tree, the first node of the tree is the dictionary key, the second layer is the Custometype collection, All code is implemented in XAML.
The code is as follows:
<treeview name= "Dictree" itemssource= "{Binding}" >
<TreeView.Resources>
<textblock text= "{Binding Id}" ><textblock text= "{Binding Name}" ></TextBlock></TextBlock>
</HierarchicalDataTemplate>
</TreeView.Resources>
<TreeView.ItemTemplate>
<textblock text= "{Binding Key}" ></TextBlock>
<HierarchicalDataTemplate.ItemTemplate>
<DataTemplate>
<textblock text= "{Binding Name}" ></TextBlock>
</DataTemplate>
</HierarchicalDataTemplate.ItemTemplate>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
Jobs JOBS1 = new jobs ();
Jobs1. ADD (New Job () {Id = 1, Name = "CEO1"});
Jobs1. ADD (New Job () {Id = 2, Name = "CEO2"});
Jobs1. ADD (New Job () {Id = 3, Name = "CEO3"});
Jobs JOBS2 = new jobs ();
JOBS2. ADD (New Job () {Id = 1, Name = "CEO1"});
JOBS2. ADD (New Job () {Id = 2, Name = "CEO2"});
JOBS2. ADD (New Job () {Id = 3, Name = "CEO3"});
dictionary<string, jobs> alljob = new dictionary<string, jobs> ();
Alljob.add ("CEO One", JOBS1);
Alljob.add ("CEO", JOBS2);
Dictree. DataContext = Alljob;
public class Job
{
public int Id
{get; set;}
public string Name
{get; set;}
public string Status
{get; set;}
}
public class Jobs:system.collections.objectmodel.observablecollection<job> {}
WPF uses Hierarchicaldatatemplate binding dictionary to generate the TreeView