WPF使用HierarchicalDataTemplate绑定Dictionary生成TreeView
2021-04-09 22:28
标签:text value aml run strong tom cer item ons Dictionary TreeView Name="dictree" ItemsSource="{Binding}"> TreeView.Resources> HierarchicalDataTemplate ItemsSource="{Binding Value}" DataType="{x:Type local:Job}"> TextBlock Text="{Binding Id}">TextBlock Text="{Binding Name}">TextBlock>TextBlock> HierarchicalDataTemplate> TreeView.Resources> TreeView.ItemTemplate> HierarchicalDataTemplate ItemsSource="{Binding Value}"> TextBlock Text="{Binding Key}">TextBlock> HierarchicalDataTemplate.ItemTemplate> DataTemplate> TextBlock Text="{Binding Name}">TextBlock> DataTemplate> HierarchicalDataTemplate.ItemTemplate> HierarchicalDataTemplate> TreeView.ItemTemplate> TreeView>
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"}); Dictionarystring, Jobs> allJob = new Dictionarystring
代码如下:
Jobs jobs1 = new Jobs();
allJob.Add("CEO one", jobs1);
allJob.Add("CEO two", 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.ObservableCollectionJob> { }
WPF使用HierarchicalDataTemplate绑定Dictionary生成TreeView
标签:text value aml run strong tom cer item ons
原文地址:https://www.cnblogs.com/lonelyxmas/p/9055534.html
上一篇:C#IO流文件操作
文章标题:WPF使用HierarchicalDataTemplate绑定Dictionary生成TreeView
文章链接:http://soscw.com/index.php/essay/73517.html