Override listviewitem background

WPF Studio, Themes, and Shared Library for WPF Forum

Posted 6 years ago by Miguel A.
Version: 18.1.0672
Platform: .NET 4.7
Environment: Windows 10 (64-bit)
Avatar

Hi,

I'm trying to overwrite the listviewitem background color based on a property. It works but only when the item is not selected or mouse hovered. How can I fix it so the background color is always blue in my case when IsMarked property is true?

 

<ListView.ItemContainerStyle>
    <Style BasedOn="{StaticResource {x:Static themes:SharedResourceKeys.ListViewItemStyleKey}}" TargetType="{x:Type ListViewItem}">
        <Style.Triggers>
            <DataTrigger Binding="{Binding Path=IsMarked}" Value="True">
                <Setter Property="Background" Value="{DynamicResource BlueBrush}" />
            </DataTrigger>
        </Style.Triggers>
    </Style>
</ListView.ItemContainerStyle>

Comments (1)

Posted 6 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Miguel,

The Background property is only used for the default normal state of the ListViewItem.  When you hover over or select the item, there are Triggers in the default ControlTemplate that will change the rendered background.  The only way to alter that behavior is to make your own custom ControlTemplate for the ListViewItem.  If you are a customer, you could use our default template as a starting point and then alter it to fit your needs.


Actipro Software Support

The latest build of this product (v24.1.1) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.