【发布时间】:2013-06-14 21:23:21
【问题描述】:
我有一个ComboBox,我绑定了一个Dictionary。代码如下:
<ComboBox Height="24" Name="comboBoxQuery" Width="300" ItemsSource="{Binding QueryNames}" SelectedItem="{Binding SelectedQueryNames}" SelectedValuePath="Key" DisplayMemberPath="Value" Visibility="{Binding Path=ComboVisibility, Converter={StaticResource BoolToVis}}" />
现在,当我尝试获取所选值时,我会得到一个包含键和值的字符串。 例如:[1, "ABC"]
我的视图模型代码:
public Dictionary<int, string> QueryNames
{
get
{
return m_ReadOnlyQueryNames;
}
set
{
m_queryNames = value;
OnPropertyChanged("QueryNames");
}
}
private string m_SelectedQueryNames;
public string SelectedQueryNames
{
get
{
return m_SelectedQueryNames;
}
set
{
if (m_SelectedQueryModule != value) <!-- value returns [1, "abc"]-->
{
m_SelectedQueryModule = value;
OnPropertyChanged("SelectedQueryNames");
}
}
}
【问题讨论】:
标签: wpf xaml data-binding dictionary combobox