在我的视图模型中,我绑定的属性是:
Products = new Dictionary<string, string>(){
{"0001", "Test Product 1"},
{"0002", "Test Product 2"},
{"0003", "Test Product 3"}
};
在我的xaml中,我有以下绑定:
<ComboBox Grid.Row="1" Grid.Column="1" DisplayMemberPath="Value" SelectedValuePath="Key" VerticalAlignment="Center"
ItemsSource="{Binding Path=DataContext.Products, RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl}}"/>
更进一步,在我的xaml中加载我的资源字典,包括表达式混合主题,如下所示:
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="AppResourceDict.xaml" />
<ResourceDictionary Source="Themes/ExpressionLight.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
以上效果很好。但是,如果我改变&#34; Themes / ExpressionLight.xaml&#34; to&#34; Themes / BureauBlue.xaml&#34;或&#34;主题/ BureauBlack.xaml&#34;,组合框下拉列表中显示的是:
["0001","Test Product 1"]
["0002","Test Product 2"]
["0003","Test Product 3"]
这些主题以某种方式导致组合框显示键+值。这是一个错误吗?有谁知道如何解决?
答案 0 :(得分:3)
看起来这是XAML中的一个错误。有一个解决方法,但它需要更改xaml:https://wpf.codeplex.com/workitem/10129
答案 1 :(得分:1)
这是主题中的错误。您可以在主题中修改控件模板,也可以在组合框中使用ItemTemplate:
<DataTemplate x:Key="ValueDataTemplate">
<TextBlock Text="{Binding Value}" />
</DataTemplate>
<ComboBox ItemTemplate="{StaticResource ValueDataTemplate}" SelectedValuePath="Key"
ItemsSource="{Binding Products}" />