突出显示.NET 4.0的ListBox和ListView [英] ListBox and ListView Highlighting .NET 4.0

查看:85
本文介绍了突出显示.NET 4.0的ListBox和ListView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在.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>

​​列表框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的变化

这篇关于突出显示.NET 4.0的ListBox和ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆