Disabled ComboBox Background

Hello,

I'd like to change the Background color of an editable ComboBox when it is disabled. I've been trying to customize the control template but I have only managed to change its Foreground color.

Any hint on how to make this change?

Thank you in advance for your help

[298 byte] By [joseluisb] at [2008-1-5]
# 1

Do you mean of the actual check box UI element? To do that you would need to completely retemplate the checkbox itself because the default template uses a hardcoded piece of rendering logic called BulletChrome. The default template is:

Code Snippet
<ControlTemplate TargetType="{x:Type CheckBox}">
<BulletDecorator SnapsToDevicePixels="true" x:Name="bulletDecorator" Background="Transparent">
<BulletDecorator.Bullet>
<Microsoft_Windows_Themes:BulletChrome Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" IsChecked="{TemplateBinding IsChecked}" RenderMouseOver="{TemplateBinding IsMouseOver}" RenderPressed="{TemplateBinding IsPressed}"/>
</BulletDecorator.Bullet>
<ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" RecognizesAccessKey="True"/>
</BulletDecorator>
<ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="True">
<Setter Property="Background" TargetName="bulletDecorator" Value="#FFFF0000"/>
</Trigger>
<Trigger Property="HasContent" Value="true">
<Setter Property="FocusVisualStyle" Value="{StaticResource CheckRadioFocusVisual}"/>
<Setter Property="Padding" Value="4,0,0,0"/>
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>

You would essentially need to replace the BulletChrome part of that with your own visuals and template bind something there to the background color. Then all you do is use a property trigger for IsDisabled=true on the CheckBox itself to set that property.

HTH,
Drew

DrewMarsh at 2007-10-3 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 2

Thank you very much for your hint Drew.

I was referring to the ComboBox control (not to CheckBox), but in any case your comments put me in the right direction. I found that the template part involved is within the ComboBoxEditableTemplate default ControlTemplate:

Code Snippet

<Microsoft_Windows_Themes:ListBoxChrome x:Name="Border" Grid.ColumnSpan="2" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" RenderFocused="{TemplateBinding IsKeyboardFocusWithin}" RenderMouseOver="{TemplateBinding IsMouseOver}"/>

joseluisb at 2007-10-3 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 3
Duh, sorry about that. Don't know how I ended up looking at the checkbox, but you're right it still applies. Glad I could help.
DrewMarsh at 2007-10-3 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...

Visual Studio Orcas

Site Classified