ListBox and ListView Highlighting .NET 4.0(ListBox 和 ListView 突出显示 .NET 4.0)
问题描述
在 .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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:ListBox 和 ListView 突出显示 .NET 4.0


- C# 中多线程网络服务器的模式 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 输入按键事件处理程序 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01