Reputation: 327
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?
Upvotes: 1
Views: 681
Reputation: 1331
Perhaps the Path on the bindings should be to a property held by the DataContext rather than the DataContext itself. That property would return the -1, -2, -3 or whatever. When that value changed, the triggers would be evaluated. The problem here is once loaded, the DataContext most likely isn't changing.
Upvotes: 1