问题描述
在 .NET 4.0 中,ListBox 和 ListView 的高亮显示发生了变化
With .NET 4.0 it appears highlighting of ListBox and ListView has changed
下面是我多年来在 .NET 3.5 的几个地方使用的代码,当不专注时突出显示已停止在 4.0 和 4.5 上工作
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
<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 背景
推荐答案
在 .NET 4.0 中有一些新的 SytemColors
这似乎是 .NET 4.0 的方式根据评论,这在 4.5 中发生了变化 - 而不是 4.0.
With .NET 4.0 there are some new SytemColors
This appears to be the .NET 4.0 way
According to 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>
一开始我虽然 ControlBrushKey 的定义变了但是没有变
在这种情况下,ControlBrushKey 的行为似乎发生了变化
At first I though the definition of ControlBrushKey had changed but it has not
It appears the behavior of ControlBrushKey has changed in this situation
注意 GridView 的行为变化
这篇关于ListBox 和 ListView 突出显示 .NET 4.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!