ListBox 和 ListView 突出显示 .NET 4.0

3

本文介绍了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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

C# 中的多播委托奇怪行为?
Multicast delegate weird behavior in C#?(C# 中的多播委托奇怪行为?)...
2023-11-11 C#/.NET开发问题
6

如何将代表存储在列表中
How to store delegates in a List(如何将代表存储在列表中)...
2023-11-11 C#/.NET开发问题
6

代表如何工作(在后台)?
How delegates work (in the background)?(代表如何工作(在后台)?)...
2023-11-11 C#/.NET开发问题
5

Delegate.CreateDelegate() 和泛型:错误绑定到目标方法
Delegate.CreateDelegate() and generics: Error binding to target method(Delegate.CreateDelegate() 和泛型:错误绑定到目标方法)...
2023-11-11 C#/.NET开发问题
14

函数委托与函数
Func Delegate vs Function(函数委托与函数)...
2023-11-11 C#/.NET开发问题
6

具有未知类型的 CreateDelegate
CreateDelegate with unknown types(具有未知类型的 CreateDelegate)...
2023-11-11 C#/.NET开发问题
5