Question

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

Was it helpful?

Solution

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>

OTHER TIPS

For me this worked - in both active and inactive ListBox, the Foreground and Background color of selected itemss are the same.

<ListBox.ItemContainerStyle>
  <Style TargetType="{x:Type ListBoxItem}">
    <Style.Resources>
      <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="DodgerBlue"/>
      <SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="White"/>
      <SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" Color="DodgerBlue"/>
      <SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightTextBrushKey}" Color="White"/>
    </Style.Resources>        
  </Style>
</ListBox.ItemContainerStyle>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top