mike01010
mike01010

Reputation: 6068

WPF: Some Expression Blend themes causing bugs in Combobox binding/display

On my view model, the property i bind to is:

    Products = new Dictionary<string, string>(){
        {"0001", "Test Product 1"},
        {"0002", "Test Product 2"},
        {"0003", "Test Product 3"}
    };

In my xaml i have the following binding:

<ComboBox Grid.Row="1" Grid.Column="1" DisplayMemberPath="Value" SelectedValuePath="Key" VerticalAlignment="Center" 
        ItemsSource="{Binding Path=DataContext.Products, RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl}}"/>

further more, in my xaml i load my resources dictionaries, include the expression blend theme like this:

<UserControl.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="AppResourceDict.xaml" />
            <ResourceDictionary Source="Themes/ExpressionLight.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</UserControl.Resources>

The above works nicely. But if i change "Themes/ExpressionLight.xaml" to "Themes/BureauBlue.xaml" or "Themes/BureauBlack.xaml", what is displayed in combobox drop down is:

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

These themes somehow are causing the combo box to display both the key + value. Is this a bug? does anyone know how to resolve?

Upvotes: 1

Views: 222

Answers (2)

Liero
Liero

Reputation: 27350

This is bug in theme. You can either modify the control template in the theme or you can still use ItemTemplate in combobox:

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

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

Upvotes: 1

mike01010
mike01010

Reputation: 6068

Looks like this is a bug in the XAML. there is a work-around but it requires changing the xaml: https://wpf.codeplex.com/workitem/10129

Upvotes: 3

Related Questions