WPF ComboBox:禁用时的背景颜色

4

我目前在WPF中使用这种样式来设置我的ComboBox:

    <Style TargetType="ComboBox">
        <Setter Property="Foreground" Value="White"/>
        <Setter Property="Background" Value="#303030"/>
        <Setter Property="BorderBrush" Value="#000000"/>
    </Style>

我该如何更改ComboBox禁用时的背景颜色?(这是对此问题的跟进:WPF combobox colors
2个回答

4
<Style TargetType="ComboBox">
    <Setter Property="Foreground" Value="White"/>
    <Setter Property="Background" Value="#303030"/>
    <Setter Property="BorderBrush" Value="#000000"/>
    <Style.Triggers>
        <Trigger Property="IsEnabled" Value="False">
            <Setter Property="Background" Value="#101010"/>
        </Trigger>
    </Style.Triggers>
</Style>

8
对我来说不起作用...如果我禁用ComboBox,背景仍然是浅灰色。 - Warpin
1
你缺少了闭合的</Style.Triggers>,但除此之外对我来说完美运行。你不必覆盖整个控件模板,只需覆盖触发器本身即可。比起查看MS链接中提供的整个ControlTemplate,这要简单得多,虽然那也很有帮助,但过于浪费...就像用火箭发射器打鸭子一样。 - DRapp

1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接