Force ListViewItem Background colour to change when bound item it is bound to changes.

Posted by hayrob on Stack Overflow See other posts from Stack Overflow or by hayrob
Published on 2010-03-30T15:46:55Z Indexed on 2010/03/30 16:13 UTC
Read the original article Hit count: 426

Filed under:
|
|

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?

© Stack Overflow or respective owner

Related posts about wpf

Related posts about c#