C# 将WPF TreeView控件绑定到KeyValuePair<;字符串,对象>;
我想让我的树视图由KeyValuePair组成,并且只显示作为标题的键。我已经在谷歌上搜索过了,找不到任何例子 到目前为止,我已经:C# 将WPF TreeView控件绑定到KeyValuePair<;字符串,对象>;,c#,wpf,treeview,C#,Wpf,Treeview,我想让我的树视图由KeyValuePair组成,并且只显示作为标题的键。我已经在谷歌上搜索过了,找不到任何例子 到目前为止,我已经: KeyValuePair<string, object> str = new KeyValuePair<string,object> (cores.Keys[i], cores.Values[i]); TreeViewItem tvi = new TreeViewItem(); tvi.Header = str; KeyValuePair
KeyValuePair<string, object> str = new KeyValuePair<string,object> (cores.Keys[i], cores.Values[i]);
TreeViewItem tvi = new TreeViewItem();
tvi.Header = str;
KeyValuePair str=新的KeyValuePair(cores.Keys[i],cores.Values[i]);
TreeViewItem tvi=新的TreeViewItem();
tvi.Header=str;
然后在xaml中:
如果您在代码隐藏中需要更多信息,请告诉我,您只需执行以下操作:
KeyValuePair<string, object> str = new KeyValuePair<string, object>(cores.Keys[i], cores.Values[i]);
List<KeyValuePair<string, object>> list = new List<KeyValuePair<string, object>>();
list.Add(str);
tvCores.ItemsSource = list;
KeyValuePair str=新的KeyValuePair(cores.Keys[i],cores.Values[i]);
列表=新列表();
添加(str);
tvCores.ItemsSource=列表;
现在,您的ItemsSource是一个KeyValuePair列表,因此在ItemsSource是一个TreeView项目之前,路径可以工作,因此路径无法工作。您的绑定是如何定义的?