簡體   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