【问题标题】:ListBox and ListView Highlighting .NET 4.0ListBox 和 ListView 突出显示 .NET 4.0
【发布时间】:2014-02-04 17:55:57
【问题描述】:

在 .NET 4.0 中,ListBox 和 ListView 的高亮显示发生了变化

下面是我多年来在 .NET 3.5 的多个地方使用的代码,当不专注时突出显示已停止在 4.0 和 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 Background

【问题讨论】:

    标签: .net wpf listbox


    【解决方案1】:

    .NET 4.0 有一些新的 SytemColors
    这似乎是 .NET 4.0 的方式 根据评论,这在 4.5 中发生了变化 - 而不是 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 的行为似乎发生了变化

    注意 GridView 的行为变化

    【讨论】:

    • 请注意SystemColors.InactiveSelectionHighlightBrushKeySystemColors.InactiveSelectionHighlightTextBrushKey 仅适用于.NET 4.5 或更高版本。它不在 .NET 4.0 中
    猜你喜欢
    • 2011-02-28
    • 1970-01-01
    • 2021-07-16
    • 1970-01-01
    • 2014-05-02
    • 2015-03-24
    • 2013-02-04
    • 2012-01-22
    • 1970-01-01
    相关资源
    最近更新 更多