KMC
KMC

Reputation: 20046

How to change ComboBox's Background Property during Mouse Hover

I have a Rounded Border containing a ComboBox as follow:

enter image description here

As soon as my mouse hover on the ComboBox, I get this

enter image description here

I want to get rid of the button-like background. I tried setting background to white or null in MouseEnter, MouseLeave, MouseUp... everything with Mouse but still I can't get rid of the default button background on the ComboBox. Does anyone has a clue?

Code below:

/* XAML */
<Border CornerRadius="11" BorderThickness="1" Height="24" Width="70" 
    Grid.Column="1" Margin="5,5,5,5" VerticalAlignment="Center" 
    HorizontalAlignment="Left" Background="White">
    <ComboBox x:Name="comboBox1" BorderBrush="{x:Null}" 
          Background="{x:Null}" Width="70" MouseMove="MouseHover"
          MouseEnter="MouseHover"
    </ComboBox>
    </Border>

/* C# code */
private void MouseHover(object sender, RoutedEventArgs e)
{
    comboBox1.Background = null;
}

Upvotes: 0

Views: 2112

Answers (2)

biju
biju

Reputation: 18000

You have to modify the default controlTemplate of the Combobox for this.Check the link below

http://social.msdn.microsoft.com/Forums/en/wpf/thread/a18891e9-8879-4819-9679-247341782f60

Upvotes: 0

Dan Puzey
Dan Puzey

Reputation: 34200

The background is set by a style trigger in the default ComboBox style, which activates when IsMouseOver is true.

There are a couple of ways around this: either override the trigger in your own style, or set BasedOn="{x:Null}" in your own ComboBox style to prevent the base style from being inherited.

Upvotes: 1

Related Questions