WPF - 仅绑定到词典键

时间:2012-10-05 09:30:35

标签: wpf data-binding dictionary listbox

我有一个绑定到词典的列表框。 字典包含关键字和字符串。

 <ListBox Style="{StaticResource ListBoxStyle}" ItemsSource="{Binding PatientImgResources, UpdateSourceTrigger=PropertyChanged}" SelectedItem="{Binding SelectedKey}"  DisplayMemberPath="Key" />

PatientImgResources是Dictionary SelectedKey是我想要的价值, DisplayMemberPath只显示关键字。

我希望这个关键字作为我的值,遗憾的是SelectedKey始终包含整个字典条目,关键字加值。 我尝试过SelectedValuePath =“Key”。到目前为止没有工作。

是否可以绑定密钥?我不想使用剥离的词典。

1 个答案:

答案 0 :(得分:1)

ItemSsource中的

绑定使用“PatientIng Resources.Keys”而不是“PatientIng Resources”......