【问题标题】:Setting listbox highlight colour to null将列表框突出显示颜色设置为 null
【发布时间】:2012-02-16 23:05:07
【问题描述】:
<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>

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

有什么想法吗?

【问题讨论】:

    标签: c# wpf listbox styles


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2012-04-25
      • 1970-01-01
      • 2011-03-24
      • 1970-01-01
      • 2013-02-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-24
      相关资源
      最近更新 更多