简体   繁体   中英

How to change ComboBox's Background Property during Mouse Hover

I have a Rounded Border containing a ComboBox as follow:

在此处输入图片说明

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

在此处输入图片说明

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;
}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM