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
WPF ComboBox: background color when disabled
提问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>