WPF uses Hierarchicaldatatemplate binding dictionary to generate the TreeView

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.