views:

32

answers:

2

I'm trying to change the background of certain items in a combobox that meet a condition

<ComboBox ItemsSource="{Binding Path=Model.Names, Mode=OneWay}" SelectedValue="{Binding Path=SelectedCompanyName}" DisplayMemberPath="Alias" />

The thing is that "Alias" is saved in two different places (in company and in order) and if they dont match we want to highlight this.

I want to do something like this:

<Style>...
    <DataTrigger Binding="{Binding Path=isMismatch}" Value="True>
        <Setter Property="Background" Value="Red" />...

Any help is appreciated.

+3  A: 

You need to create custom data template like this:

<ComboBox Width="300" Height="30" ItemsSource="{Binding Path=Model.Names, Mode=OneWay}">
    <ComboBox.ItemTemplate>
        <DataTemplate>
            <Grid x:Name="templateGrid">
                <TextBox Text="{Binding Name}" />
            </Grid>
            <DataTemplate.Triggers>
                <DataTrigger Binding="{Binding isMismatch}" Value="True">
                   <Setter TargetName="templateGrid" 
                           Property="Background" Value="Red" />         
                </DataTrigger>
            </DataTemplate.Triggers>
        </DataTemplate>
    </ComboBox.ItemTemplate>
</ComboBox>
Nagg
Works thanks. New problem is that Alias and IsMismatch are not at the same place... :)
debe
A: 

If you want to highlight the selection based on the values of two properties, I think you could use a MultiValueConverter, together with a MultiBinding.

Jens