4

I currently use this style for my ComboBox in WPF:

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

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

Community
  • 1
  • 1
Warpin
  • 6,971
  • 12
  • 51
  • 77

2 Answers2

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>
Miquella
  • 1,074
  • 2
  • 13
  • 25
Charlie
  • 15,069
  • 3
  • 64
  • 70
  • 8
    Doesn't work for me... if I disable the ComboBox the background is still light gray. – Warpin Mar 05 '10 at 18:36
  • 1
    You are missing the closing , but otherwise worked perfectly for me. You don't have to overwrite the entire control template, just the trigger itself.. Much simpler than looking at the entire ControlTemplate provided in the MS link, although that too is helpful, but overkill.... like duck hunting with a rocket launcher. – DRapp Oct 19 '11 at 16:29
1

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

Warpin
  • 6,971
  • 12
  • 51
  • 77