简体   繁体   English

ListBox和ListView突出显示.NET 4.0

[英]ListBox and ListView Highlighting .NET 4.0

With .NET 4.0 it appears highlighting of ListBox and ListView has changed 使用.NET 4.0,它会突出显示ListBox和ListView已更改

Below is code I have used for years in several places on .NET 3.5 and highlight when not focused has stopped working on 4.0 and 4.5 下面是我在.NET 3.5上的几个地方使用多年的代码,并突出显示未聚焦时已经停止在4.0和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>

ListBox SelectedItem Background ListBox SelectedItem背景

With .NET 4.0 there are some new SytemColors 使用.NET 4.0,有一些新的SytemColors
This appears to be the .NET 4.0 way According to comment this changed in 4.5 - not 4.0. 这似乎是.NET 4.0的方式根据评论,这改变了4.5 - 而不是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 though the definition of ControlBrushKey had changed but it has not 起初我虽然ControlBrushKey的定义发生了变化,但事实并非如此
It appears the behavior of ControlBrushKey has changed in this situation 在这种情况下,ControlBrushKey的行为似乎已发生变化

Note the behavior changes with GridView 请注意,GridView的行为会发生变化

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM