删除自定义组合框样式wpf的MouseOver效果

问题描述 投票:0回答:1

在我的wpf文档中,我制作了一个自定义的组合框样式,如下所示:

<ComboBox Background="#222222" BorderBrush="Black" Grid.Column="1" Height="30" Width="250">
<ComboBox.Resources>
    <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="#262626" />
</ComboBox.Resources>
<ComboBox.ItemContainerStyle>
    <Style TargetType="{x:Type ComboBoxItem}">
        <Style.Triggers> <Trigger Property="IsMouseOver" Value="true"> <Setter Property="Background" Value="#262626" /> </Trigger> </Style.Triggers>
    </Style>
</ComboBox.ItemContainerStyle>
<ComboBoxItem Foreground="White" Name="Item1">Item1

</ComboBoxItem>
<ComboBoxItem Foreground="White" Name="Item2">Item2</ComboBoxItem>
<ComboBoxItem Foreground="White" Name="Item3">Item3</ComboBoxItem>
<ComboBoxItem Foreground="White" Name="Item4">Item4</ComboBoxItem>
<ComboBoxItem Foreground="White" Name="Item5">Item5</ComboBoxItem>
<ComboBoxItem Foreground="White" Name="Item6">Item6</ComboBoxItem>

但是只要将鼠标悬停在ComboboxItem之一上,我仍然会获得默认的悬停颜色,那么如何删除它并放置颜色?

我相对较不熟悉编码,因此不胜感激。

wpf combobox mouseover styling
1个回答
0
投票
您必须覆盖ControlTemplate的默认ComboBoxItem,才能覆盖默认的视觉状态触发器。检查Microsoft Docs: Control Styles and Templates以查看框架控件的默认Style实现。
© www.soinside.com 2019 - 2024. All rights reserved.