2015-02-24 79 views
1

在我的视图模型,物业我绑定的是:WPF:一些导致错误的组合框Expression Blend的主题结合/显示

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> 

上面很好地工作。但是,如果我改变“主题/ ExpressionLight.xaml”为“主题/ BureauBlue.xaml”或“主题/ BureauBlack.xaml”,什么是显示在组合框中的下拉是:

["0001","Test Product 1"] 
["0002","Test Product 2"] 
["0003","Test Product 3"] 

这些主题在某种程度上是造成组合框显示键+值。这是一个错误?有谁知道如何解决?

回答

1

这是主题中的错误。您可以修改主题中的控件模板,也可以在组合框中使用ItemTemplate:

<DataTemplate x:Key="ValueDataTemplate"> 
    <TextBlock Text="{Binding Value}" /> 
</DataTemplate> 

<ComboBox ItemTemplate="{StaticResource ValueDataTemplate}" SelectedValuePath="Key" 
    ItemsSource="{Binding Products}" />