Force ListViewItem Background colour to change when bound item it is bound to changes.
- by hayrob
My ItemContainerStyle works perfectly when a ListViewItem is added:
<Style x:Key="ItemContStyle"
TargetType="{x:Type ListViewItem}">
<Style.Resources>
<SolidColorBrush x:Key="lossBrush"
Color="Red" />
<SolidColorBrush x:Key="newPartNo"
Color="LightGreen" />
<SolidColorBrush x:Key="noSupplier"
Color="Yellow" />
<Orders:OrderItemStatusConverter x:Key="OrderItemConverter" />
</Style.Resources>
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=DataContext, Converter={StaticResource OrderItemConverter}}"
Value="-1">
<Setter Property="Background"
Value="{StaticResource lossBrush}" />
</DataTrigger>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Self},Path=DataContext, Converter={StaticResource OrderItemConverter}}"
Value="-2">
<Setter Property="Background"
Value="{StaticResource newPartNo}" />
</DataTrigger>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Self},Path=DataContext, Converter={StaticResource OrderItemConverter}}"
Value="-3">
<Setter Property="Background"
Value="{StaticResource noSupplier}" />
</DataTrigger>
</Style.Triggers>
</Style>
However when the source item changes, the trigger is not fired and the background colour is not what I expect.
How can I make the trigger fire?