5

我有这种简单的样式,在禁用ListBox Background时不会改变:ListBox

<Style TargetType="ListBox" >                    
    <Style.Triggers>
        <Trigger Property="IsEnabled" Value="True">
            <Setter Property="Background" Value="Red"/>
        </Trigger>
        <Trigger Property="IsEnabled" Value="False">
            <Setter Property="Background" Value="Orange"/>
        </Trigger>
    </Style.Triggers>
</Style>

Snoop 在这方面对我没有帮助,如果不覆盖模板,我无法找到一种简单的方法。任何人都有一个简单的方法来得到这个工作?TIA。

4

2 回答 2

2

唯一的方法是覆盖模板

于 2012-01-31T17:55:24.067 回答
0

当列表框被禁用时,您可以通过更改内置模板使用的颜色来更改列表框本身的背景颜色。您可以通过样式资源来做到这一点。只需将以下代码粘贴到您的 Listbox 元素中,当您禁用该框时,背景将是透明的。

<ListBox.Style>
    <Style TargetType="{x:Type ListBox}">
        <Style.Resources>
            <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent"/>
        </Style.Resources>
    </Style>
</ListBox.Style>

当单个项目突出显示并且框失去焦点时,想要修改它的背景颜色也很常见。要更改这些,您可以参考这篇文章: https ://stackoverflow.com/a/7298301/1721136

于 2013-06-12T21:57:09.347 回答