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.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With