WPF:某些Expression Blend主题导致组合框绑定/显示中出现错误
本文关键字:绑定 显示 错误 组合 Expression 某些 Blend WPF | 更新日期: 2024-07-27 20:55:36
在我的视图模型上,我绑定到的属性是:
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>
上面的效果很好。但是,如果我将"Themes/ExpressionLight.xml"更改为"Themes/BackagesBlue.xml"或"Themes/KackagesBlack.xml",则组合框下拉菜单中显示的内容为:
["0001","Test Product 1"]
["0002","Test Product 2"]
["0003","Test Product 3"]
这些主题以某种方式导致组合框同时显示键+值。这是个虫子吗?有人知道如何解决吗?
看起来这是XAML中的一个错误。有一个解决方案,但它需要更改xaml:https://wpf.codeplex.com/workitem/10129
这是主题中的错误。您可以修改主题中的控制模板,也可以在组合框中使用ItemTemplate:
<DataTemplate x:Key="ValueDataTemplate">
<TextBlock Text="{Binding Value}" />
</DataTemplate>
<ComboBox ItemTemplate="{StaticResource ValueDataTemplate}" SelectedValuePath="Key"
ItemsSource="{Binding Products}" />