WPF ComboBox:禁用时的背景颜色

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2388833/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 21:32:44  来源:igfitidea点击:

WPF ComboBox: background color when disabled

wpfwindowscomboboxcolors

提问by Warpin

I currently use this style for my ComboBox in WPF:

我目前在 WPF 中为我的 ComboBox 使用这种样式:

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

How can I change it to specify the background color when the ComboBox is disabled?

当 ComboBox 被禁用时,如何更改它以指定背景颜色?

(this is a follow-up to this question: WPF combobox colors)

(这是这个问题的后续:WPF 组合框颜色

采纳答案by Warpin

I ended up using the style used here as a base, and this did allow to set the background color when disabled:

我最终使用这里使用的样式作为基础,这确实允许在禁用时设置背景颜色:

http://msdn.microsoft.com/en-us/library/ms752094%28v=VS.85%29.aspx

http://msdn.microsoft.com/en-us/library/ms752094%28v=VS.85%29.aspx

回答by Charlie

<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>