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
基础教程推荐
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- WPF 模态进度窗口 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
