将列表框突出显示颜色设置为空

本文关键字:颜色 设置 显示 列表 | 更新日期: 2023-09-27 18:24:50

<Style TargetType="ListBoxItem">
        <Style.Resources>
            <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent" />
            <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent" />
            </Style.Resources>
        <Style.Triggers>
            <Trigger Property="IsSelected" Value="True">
                <Setter Property="Background" Value="White" />                   
            </Trigger>
        </Style.Triggers>
     </Style>

上面的代码旨在防止将任何突出显示颜色用作列表框项的"选择指示器"。我的程序有一个完全白色的背景,我打算使用一些自定义动画来表示选择。上面的代码确实删除了传统的蓝色突出显示,但它也使文本(在项目容器内(完全消失,所以我看到的只是一个白色项目。

有什么想法吗?

将列表框突出显示颜色设置为空

在您的样式中,在 IsSelected 触发器中,添加一个 Setter 以将前景设置为所需的颜色而不是白色。 我通常在 ItemContainerStyle 中执行此操作,但它也应该在您的 ListBoxItem 样式中工作。