WPF ComboBox ControlTemplate Background problem

973 views Asked by At

This is an example of a ComboBox's ControlTemplate.

CLICK HERE

I've tried to set the Background / add a trigger to change the background when the ComboBox is focused (with a tab key for example), both without success. I don't even understand why it isn't included by default ! (compared to the original generic template)

1

There are 1 answers

1
Steven On

Do you mean change the background of the ComboBoxItem when it is focused? Its not normal to change the background of an entire ComboBox. Keep in mind that the template is different for editable ComboBoxes.

From looking at the template you referenced, the Background property is used for the ComboBox dropdown. So you're trigger needs to target that outter most Grid. Did you try adding triggers like these?

<Trigger Property="IsKeyboardFocusWithin" Value="True">
    <Setter TargetName="[outtermostgrid]" Property="Background" Value="Red" />
</Trigger>
<Trigger Property="IsDropdownOpen" Value="True">
    <Setter TargetName="[outtermostgrid]" Property="Background" Value="Red" />
</Trigger>