c# - 将值从字典绑定到 ComboBox
问题描述
我有一个清单:
public SortedDictionary<string, string> ProjectDictionaryList { get; internal set; }
现在我想将值绑定到 ComboBox:
ComboBox DockPanel.Dock="Right" ItemsSource="{Binding Path=ProjectDictionaryList}"
IsSynchronizedWithCurrentItem="True" Style="{StaticResource myCombo}"
SelectedItem="{Binding SelectedProject}"
但是怎么绑定ProjectDictionaryList.Value
?
解决方案
设置DisplayMemberPath
和SelectedValuePath
绑定SelectedValue
以通过其键选择字典条目:
<ComboBox
ItemsSource="{Binding ProjectDictionaryList}"
DisplayMemberPath="Value"
SelectedValuePath="Key"
SelectedValue="{Binding SelectedProject}"/>
推荐阅读
- python - Python UDP 服务器无法接受客户端连接
- ubuntu - Netcat 抛出“getnameinfo:名称解析临时失败”错误
- elasticsearch - 如何创建一个记录到特定 Elasticsearch 索引的 Laravel Logger?
- html - 如何在记事本++中的标签内换行段落或文本
- python - 如何让 UDP 服务器在 Python 中不断接收数据报
- java - 如何同时按下多个键?JavaFX
- angular - 通过选择器(sidenav)不可见角度组件
- pandas - Python:如何从熊猫的特定列中获取价值?
- javascript - 将json发送到数据库
- c++ - C ++中方格的邻接矩阵