2

Just a quick question. Can i use ListView.Resources and ListView.ItemContainerStyle at the same time. It seems only one of them is working if i use together..

<ListView.Resources>
    <Style TargetType="{x:Type ListViewItem}">
        <Style.Triggers>
            <DataTrigger Binding="{Binding PAMStatus}" Value="ACTIVE">
                <Setter Property="Background" Value="DimGray" />
            </DataTrigger>

        </Style.Triggers>

<ListView.ItemContainerStyle>
    <Style TargetType="ListViewItem">
        <Setter Property="HorizontalContentAlignment" Value="Stretch" />
    </Style>
</ListView.ItemContainerStyle>
mm8
  • 163,881
  • 10
  • 57
  • 88
AliAzra
  • 889
  • 1
  • 9
  • 28

1 Answers1

3

It seems only one of them is working if i use together..

Yes, there can only be one style applied to the ListViewItem(s).

But you can "extend" a style by creating a new one that is based on the original one:

<ListView ...>
    <ListView.Resources>
        <Style x:Key="style" TargetType="{x:Type ListViewItem}">
            <Style.Triggers>
                <DataTrigger Binding="{Binding PAMStatus}" Value="ACTIVE">
                    <Setter Property="Background" Value="DimGray" />
                </DataTrigger>

            </Style.Triggers>
        </Style>
    </ListView.Resources>
    <ListView.ItemContainerStyle>
        <Style TargetType="ListViewItem" BasedOn="{StaticResource style}">
            <Setter Property="HorizontalContentAlignment" Value="Stretch" />
        </Style>
    </ListView.ItemContainerStyle>
</ListView>

How to create a style based on default style?

mm8
  • 163,881
  • 10
  • 57
  • 88