【问题标题】:WPF - Bind to Dictionary Key OnlyWPF - 仅绑定到字典键
【发布时间】:2012-09-26 10:36:49
【问题描述】:

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

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

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

我希望这个关键字作为我的值,不幸的是 SelectedKey 总是包含整个字典条目,关键字加值。 我试过 SelectedValuePath="Key" 。到目前为止还没有工作。

是否可以绑定到密钥?我不想使用精简的字典。

【问题讨论】:

    标签: wpf data-binding dictionary listbox


    【解决方案1】:

    在 ItemSource Binding 中使用“PatientImgResources.Keys”而不是“PatientImgResources”...

    【讨论】:

    • 尝试使用“Keys”代替“Key”... PatientImgResources.Keys
    猜你喜欢
    • 2011-01-23
    • 1970-01-01
    • 2011-02-28
    • 1970-01-01
    • 2016-11-20
    • 1970-01-01
    • 2014-12-23
    • 2011-03-27
    • 2015-10-28
    相关资源
    最近更新 更多