ListBox and ListView.NET 4.0 Selection

With .NET 4.0, ListBox and ListView selection with modified

Below is the code that I used for several years in several places on .NET 3.5 and highlight, when not focused, it stops working with 4.0 and 4.5

<ListBox.ItemContainerStyle>
    <Style>
        <Style.Resources>
            <SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Red"/>
            <!-- Background of selected item when focussed -->
            <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Pink"/>
            <!-- Background of selected item when not focussed -->
            <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Yellow" />
        </Style.Resources>
    </Style>
</ListBox.ItemContainerStyle>

Source ListBox

+3
source share
1 answer

New SytemColors Introduced with .NET 4.0
This is similar to the .NET 4.0 method. According to the comment, this changed in 4.5 - not 4.0.

<ListBox.ItemContainerStyle>
    <Style>
        <Style.Resources>
            <!-- Foregroud of selected item when focussed -->
            <SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Red"/>
            <!-- Foregroud of selected item when not focussed -->
            <SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightTextBrushKey}" Color="Green"/>
            <!-- Background of selected item when focussed -->
            <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Pink"/>
            <!-- Background of selected item when not focussed -->
            <SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" Color="Yellow" />
        </Style.Resources>
    </Style>
</ListBox.ItemContainerStyle> 

At first I, although the definition of ControlBrushKey changed, but it was not. It seems that the behavior of ControlBrushKey changed in this situation

Notice Behavioral Changes Using GridView

+2
source

All Articles