繁体   English   中英

将WPF TreeView控件绑定到KeyValuePair <string,object>

[英]Binding a WPF TreeView control to a KeyValuePair<string,object>

我想建立KeyValuePair的树视图,并且只将键显示为标题。 我已经用谷歌搜索了,找不到任何例子。

到目前为止,我有:

KeyValuePair<string, object> str = new KeyValuePair<string,object> (cores.Keys[i], cores.Values[i]);
TreeViewItem tvi = new TreeViewItem();
tvi.Header = str;

然后在xaml中: <TreeView Name="tvCores" Grid.Column="0" PreviewMouseRightButtonDown="OnPreviewMouseRightButtonDown" DisplayMemberPath="Key"/ >

请让我知道是否需要更多信息

在后面的代码中,您只需要执行以下操作:

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;

现在,您的ItemsSource是KeyValuePair的列表,因此该路径可以使用,而ItemsSource是TreeViewItem之前,因此该路径无法使用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM