views:

1109

answers:

1

Hello,

I'm able to set ListView Inactive Selection Color

I used solution described in following question

http://stackoverflow.com/questions/382006/wpf-listview-inactive-selection-color

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

Thank You

+4  A: 

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>

HTH, Kent

Kent Boogaart
Thank You for you answer, but unfortunately selected element becomes gray, when ListBox looses focus :(I would foreground to be white and background blue, when element is selected, but inactive.
Daniil Harik
Updated my answer.
Kent Boogaart