删除自定义组合框样式wpf上的鼠标悬停效果

删除自定义组合框样式wpf上的鼠标悬停效果,wpf,combobox,mouseover,styling,Wpf,Combobox,Mouseover,Styling,在我的wpf文档中,我制作了如下自定义组合框样式: <ComboBox Background="#222222" BorderBrush="Black" Grid.Column="1" Height="30" Width="250"> <ComboBox.Resources> <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="#262626" /> <

在我的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>

项目1
项目2
项目3
项目4
项目5
项目6

但是,每当我将鼠标悬停在其中一个ComboboxItems上时,我仍然会得到默认的悬停颜色,那么如何删除它并放置我的颜色呢


我对编码比较陌生,因此希望您能提供帮助。

您必须覆盖
ComboBoxItem
的默认
ControlTemplate
,以覆盖默认的可视状态触发器。
检查以查看框架控件的默认
样式
实现

ComboBoxItem
Style

<ComboBox>
  <ComboBox.ItemContainerStyle>
    <Style TargetType="ComboBoxItem">
      <Setter Property="Template">
        <Setter.Value>
          <ControlTemplate TargetType="ComboBoxItem">
            <Border BorderBrush="{TemplateBinding BorderBrush}"
                    BorderThickness="{TemplateBinding BorderThickness}"
                    Background="{TemplateBinding Background}">
              <ContentPresenter />
            </Border>

            <ControlTemplate.Triggers> 
              <Trigger Property="IsMouseOver" 
                       Value="True"> 
                <Setter Property="Background" 
                        Value="#262626" /> 
              </Trigger> 
            </ControlTemplate.Triggers>
          </ControlTemplate>
        </Setter.Value>
      <Setter>
    </Style>
  </ComboBox.ItemContainerStyle>
</ComboBox>