Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将WPF TreeView控件绑定到KeyValuePair<;字符串,对象>;_C#_Wpf_Treeview - Fatal编程技术网

C# 将WPF TreeView控件绑定到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组成,并且只显示作为标题的键。我已经在谷歌上搜索过了,找不到任何例子

到目前为止,我已经:

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项目之前,路径可以工作,因此路径无法工作。

您的绑定是如何定义的?