Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF ListView Inactive Selection Color and element font color

I'm able to set ListView Inactive Selection Color

I used solution described in following question

WPF ListView Inactive Selection Color

I need to change font color of selected inactive element, is there easy way to accomplish this?

Thank You

like image 267
Daniil Harik Avatar asked Dec 17 '22 08:12

Daniil Harik


1 Answers

Unfortunately, you can't use SystemColors.ControlTextBrushKey because it applies when the item is unselected, or when it is selected but inactive (your question reads as though you're only interested in the latter). However, you can do this:

<ListBox ...>
    <ListBox.Resources>
        <!-- this customizes the background color when the item is selected but inactive -->
        <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}">Red</SolidColorBrush>
    </ListBox.Resources>
    <ListBox.ItemContainerStyle>
        <Style>
            <Style.Triggers>
                            <!-- this customizes the foreground color when the item is selected but inactive -->
                <Trigger Property="Selector.IsSelected" Value="True">
                    <Setter Property="TextElement.Foreground" Value="Blue"/>
                </Trigger>
            </Style.Triggers>
        </Style>
    </ListBox.ItemContainerStyle>
</ListBox>
like image 128
Kent Boogaart Avatar answered Feb 15 '23 04:02

Kent Boogaart