WPF组合框默认悬停颜色在togglebutton上

时间:2014-11-12 16:40:34

标签: wpf combobox

我有一个组合框,它就像一个没有箭头的简单吧。几乎可以做出各种颜色变化,除了我在悬停在组合框本身上时无法弄清楚如何更改默认的蓝色。非常感谢您的帮助。

令人讨厌的是样式中的部分似乎是我的答案所在,但即使对它进行全面评论也没有引起构建comboBox的任何问题,所以我想知道我是否必须覆盖某些东西来实现这一点。这是被称为“ComboBoxTextBoxTemplate”的部分

<Style TargetType="{x:Type ComboBox}">
    <Setter Property="Foreground" Value="White" />
    <Setter Property="BorderBrush" Value="White" />
    <Setter Property="Background" Value="White" />
    <Setter Property="SnapsToDevicePixels" Value="true"/>
    <Setter Property="OverridesDefaultStyle" Value="true"/>
    <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
    <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
    <Setter Property="ScrollViewer.CanContentScroll" Value="true"/>
    <Setter Property="FontFamily" Value="Resources/#AGENCYR" />
    <Setter Property="FontSize" Value="16" />
    <Setter Property="FontWeight" Value="Normal"/>
    <Setter Property="HorizontalAlignment" Value="Left"/>
    <Setter Property="VerticalAlignment" Value="Top" />
    <Setter Property="Cursor" Value="Arrow"/>
    <Setter Property="Height" Value="34"/>
    <Setter Property="Width" Value="387"/>
    <Setter Property="MinWidth" Value="50"/>
    <Setter Property="MinHeight" Value="32"/>
    <Setter Property="Control.Template">
        <Setter.Value>
            <ControlTemplate TargetType="ComboBox">
                <Grid>
                    <ToggleButton ClickMode="Press" Name="ToggleButton" Grid.Column="2" Focusable="False"
        IsChecked="{Binding Path=IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}"
        Template="{StaticResource ComboBoxToggleButtonTemplate}"/>
                    <ContentPresenter
        Margin="3,3,23,3"
        HorizontalAlignment="Left"
        Name="ContentSite"
        VerticalAlignment="Center"
        ContentTemplate="{TemplateBinding ComboBox.SelectionBoxItemTemplate}"
        Content="{TemplateBinding ComboBox.SelectionBoxItem}"
        IsHitTestVisible="False" />
                    <TextBox
        Margin="3,3,23,3"
        Visibility="Hidden"
        HorizontalAlignment="Left"
        Name="PART_EditableTextBox"
        Background="Transparent"
        VerticalAlignment="Center"
        Style="{x:Null}"
        IsReadOnly="False"
        Focusable="True"
        xml:space="preserve"
        Template="{StaticResource ComboBoxTextBoxTemplate}"/>
                    <Popup
        Placement="Bottom"
        Name="Popup"
        Focusable="False"
        AllowsTransparency="True"
        IsOpen="{TemplateBinding ComboBox.IsDropDownOpen}"
        PopupAnimation="Fade">
      <Grid
          MinWidth="{TemplateBinding FrameworkElement.ActualWidth}"
          MaxHeight="{TemplateBinding ComboBox.MaxDropDownHeight}"
          Name="DropDown"
          SnapsToDevicePixels="True">
        <Border
            BorderBrush="{StaticResource NormalBorderBrush}"
            BorderThickness="1,1,1,1"
            Name="DropDownBorder"
            Background="{StaticResource WindowBackgroundBrush}"/>
        <ScrollViewer
            Margin="4,6,4,6"
            SnapsToDevicePixels="True">
          <ItemsPresenter
              KeyboardNavigation.DirectionalNavigation="Contained" />
        </ScrollViewer>
      </Grid>
    </Popup>
            </Grid>
                <ControlTemplate.Triggers>
                    <Trigger Property="UIElement.IsMouseOver" Value="True">
                        <Setter Property="Panel.Background" Value="Red"/>
                    </Trigger>
                    <Trigger Property="ItemsControl.HasItems" Value="False">
                        <Setter Property="FrameworkElement.MinHeight" TargetName="DropDownBorder" Value="95"/>
                    </Trigger>
                    <Trigger Property="UIElement.IsEnabled" Value="False">
                        <Setter Property="TextElement.Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
                    </Trigger>
                    <Trigger Property="ItemsControl.IsGrouping" Value="True">
                        <Setter Property="ScrollViewer.CanContentScroll" Value="False"/>
                    </Trigger>
                    <Trigger Property="Window.AllowsTransparency" SourceName="Popup" Value="True">
                        <Setter Property="Border.CornerRadius" TargetName="DropDownBorder" Value="4"/>
                        <Setter Property="FrameworkElement.Margin" TargetName="DropDownBorder" Value="0,2,0,0"/>
                    </Trigger>
                    <Trigger Property="ComboBox.IsEditable" Value="True">
                        <Setter Property="KeyboardNavigation.IsTabStop" Value="False"/>
                        <Setter Property="UIElement.Visibility" TargetName="PART_EditableTextBox" Value="Visible"/>
                        <Setter Property="UIElement.Visibility" TargetName="ContentSite" Value="Hidden"/>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>

    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="ComboBox">
                <Grid>
                    <ToggleButton
                        Name="ToggleButton"
                        BorderBrush="Gray"
                        BorderThickness="0"
                        Background="Gray"
                        Grid.Column="2"
                        Focusable="false"
                        IsChecked="{Binding Path=IsDropDownOpen,Mode=TwoWay,RelativeSource={RelativeSource TemplatedParent}}"
                        ClickMode="Release">
                    </ToggleButton>
                    <ContentPresenter
                        Name="ContentSite"
                        IsHitTestVisible="False"
                        Content="{TemplateBinding SelectionBoxItem}"
                        ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
                        ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
                        Margin="10,3,30,3"
                        VerticalAlignment="Center"
                        HorizontalAlignment="Center" />
                    <Popup
                        Name="Popup"
                        Placement="Bottom"
                        IsOpen="{TemplateBinding IsDropDownOpen}"
                        AllowsTransparency="True"
                        Focusable="False"
                        PopupAnimation="Fade">
                        <Grid
                            Name="DropDown"
                            SnapsToDevicePixels="True"
                            MinWidth="{TemplateBinding ActualWidth}"
                            MaxHeight="{TemplateBinding MaxDropDownHeight}">
                            <Border
                            x:Name="DropDownBorder"
                            Background="White"
                            BorderThickness="1"
                            BorderBrush="Black"/>
                            <ScrollViewer Margin="4,6,4,6" SnapsToDevicePixels="True">
                                <StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Contained" />
                            </ScrollViewer>
                        </Grid>
                    </Popup>
                </Grid>
                <ControlTemplate.Triggers>
                    <Trigger Property="HasItems" Value="false">
                        <Setter TargetName="DropDownBorder" Property="MinHeight" Value="95"/>
                    </Trigger>
                    <Trigger Property="IsGrouping" Value="true">
                        <Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
                    </Trigger>
                    <Trigger SourceName="Popup" Property="Popup.AllowsTransparency" Value="true">
                        <Setter TargetName="DropDownBorder" Property="CornerRadius" Value="0"/>
                        <Setter TargetName="DropDownBorder" Property="Margin" Value="0,2,0,0"/>
                    </Trigger>
                    <Trigger Property="IsEditable" Value="true">
                        <Setter Property="IsTabStop" Value="false"/>
                        <Setter TargetName="ContentSite" Property="Visibility" Value="Hidden"/>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

<Style TargetType="{x:Type ComboBoxItem}">
    <Setter Property="Foreground" Value="Black" />
    <Setter Property="Control.Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type ComboBoxItem}">
                <Border
                  Name="Border"
                  SnapsToDevicePixels="True"
                  Padding="2,2,2,2">
                    <ContentPresenter/>
                </Border>
                <ControlTemplate.Triggers>
                    <Trigger Property="ComboBoxItem.IsHighlighted" Value="True">
                        <Setter Property="Panel.Background" TargetName="Border" Value="{StaticResource CustomBrush1}"/>
                    </Trigger>
                    <Trigger Property="UIElement.IsEnabled" Value="False">
                        <Setter Property="TextElement.Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
    <Style.Resources>
        <SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}"/>
        <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}"/>
    </Style.Resources>
    <Style.Triggers>
        <Trigger Property="IsMouseOver" Value="True" >
            <Setter Property="Foreground" Value="White" />
            <Setter Property="Background" Value="#24afb2" />
        </Trigger>
        <Trigger Property="IsSelected" Value="True" >
            <Setter Property="Background" Value="#24afb2" />
            <Setter Property="Foreground" Value="White" />
        </Trigger>
        <MultiTrigger>
            <MultiTrigger.Conditions>
                <Condition Property="IsFocused" Value="True"/>
                <Condition Property="IsMouseOver" Value="False"/>
            </MultiTrigger.Conditions>
            <Setter Property="Foreground" Value="White" />
            <Setter Property="Background" Value="#24afb2" />
        </MultiTrigger>
        <MultiTrigger>
            <MultiTrigger.Conditions>
                <Condition Property="IsSelected" Value="True"/>
                <Condition Property="IsMouseOver" Value="False"/>
            </MultiTrigger.Conditions>
            <Setter Property="Foreground" Value="Black" />
        </MultiTrigger>
    </Style.Triggers>
</Style>

<ControlTemplate TargetType="TextBox" x:Key="ComboBoxTextBoxTemplate">
    <Border
Name="PART_ContentHost"
Background="Gray"
Focusable="False" />
</ControlTemplate>

<ControlTemplate TargetType="ToggleButton" x:Key="ComboBoxToggleButtonTemplate">
    <!--<Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition Width="16" />
        </Grid.ColumnDefinitions>
        <Border
  BorderBrush="Black"
  CornerRadius="2,2,2,2"
  BorderThickness="1,1,1,1"
  Name="Border"
  Background="WhiteSmoke"
  Grid.ColumnSpan="2" />
        <Border
  Margin="1,1,1,1"
  BorderBrush="{StaticResource NormalBorderBrush}"
  CornerRadius="2,0,0,2"
  BorderThickness="0,0,1,0"
  Background="AliceBlue"
  Grid.Column="0" />
        <Path
  Margin="0,0,3,0"
  Data="M0,0L4,4 8,0z"
  HorizontalAlignment="Center"
  Fill="{StaticResource GlyphBrush}"
  Name="Arrow"
  VerticalAlignment="Center"
  Width="8"
  Grid.Column="1" />
    </Grid>
    <ControlTemplate.Triggers>
        <Trigger Property="UIElement.IsMouseOver" Value="True">
            <Setter Property="Panel.Background" TargetName="Border" Value="WhiteSmoke"/>
        </Trigger>
        <Trigger Property="ToggleButton.IsChecked" Value="True">
            <Setter Property="Panel.Background" TargetName="Border" Value="WhiteSmoke"/>
            <Setter Property="Shape.Fill" TargetName="Arrow" Value="#FF8D979E"/>
        </Trigger>
        <Trigger Property="UIElement.IsEnabled" Value="False">
            <Setter Property="Panel.Background" TargetName="Border" Value="{StaticResource DisabledBackgroundBrush}"/>
            <Setter Property="Border.BorderBrush" TargetName="Border" Value="{StaticResource DisabledBorderBrush}"/>
            <Setter Property="TextElement.Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
            <Setter Property="Shape.Fill" TargetName="Arrow" Value="#66FFFFFF"/>
        </Trigger>
    </ControlTemplate.Triggers>-->
</ControlTemplate>


<!-- The Actual ComboBox -->
<Grid>
    <ComboBox x:Name="cmbNames" ItemsSource="{Binding SelectedName}" DisplayMemberPath ="FirstName" Width="454">
    </ComboBox>
    <TextBlock x:Name="txtComboBox" Style="{StaticResource ComboTextBox}" 
               Visibility="{Binding SelectedItem, ElementName=cmbNames, Converter={StaticResource NullToVisibilityConverter}}"
         Text=" Select ..." />
</Grid>

2 个答案:

答案 0 :(得分:0)

我已经尽力弄清楚你在这里想要完成什么,我做了一些调整,至少应该让你达到一个合理的起点。我不得不改进颜色,因为你遗漏了一些你引用的画笔资源;)。

<SolidColorBrush x:Key="CustomBrush1"
                 Color="Magenta" />
<SolidColorBrush x:Key="DisabledForegroundBrush"
                 Color="Gray" />
<SolidColorBrush x:Key="DisabledBackgroundBrush"
                 Color="Gray" />
<SolidColorBrush x:Key="DisabledBorderBrush"
                 Color="Gray" />
<SolidColorBrush x:Key="NormalBorderBrush"
                 Color="Black" />

<DrawingBrush x:Key="GlyphBrush">
  <DrawingBrush.Drawing>
    <GeometryDrawing Brush="Black"
                     Geometry="M 0,0 L 4,4 L 8,0 Z" />
  </DrawingBrush.Drawing>
</DrawingBrush>

<ControlTemplate TargetType="TextBox"
                 x:Key="ComboBoxTextBoxTemplate">
  <Border Name="PART_ContentHost"
          Background="Gray"
          Focusable="False" />
</ControlTemplate>

<ControlTemplate TargetType="ToggleButton"
                 x:Key="ComboBoxToggleButtonTemplate">
  <Grid>
    <Grid.ColumnDefinitions>
      <ColumnDefinition />
      <ColumnDefinition Width="16" />
    </Grid.ColumnDefinitions>
    <Border BorderBrush="Black"
            CornerRadius="2,2,2,2"
            BorderThickness="1,1,1,1"
            Name="Border"
            Background="WhiteSmoke"
            Grid.ColumnSpan="2" />
    <Path Margin="0,0,3,0"
          Data="M0,0L4,4 8,0z"
          HorizontalAlignment="Center"
          Fill="{StaticResource GlyphBrush}"
          Name="Arrow"
          VerticalAlignment="Center"
          Width="8"
          Grid.Column="1" />
  </Grid>
  <ControlTemplate.Triggers>
    <Trigger Property="UIElement.IsMouseOver"
             Value="True">
      <Setter Property="Panel.Background"
              TargetName="Border"
              Value="DodgerBlue" />
    </Trigger>
    <Trigger Property="ToggleButton.IsChecked"
             Value="True">
      <Setter Property="Panel.Background"
              TargetName="Border"
              Value="WhiteSmoke" />
      <Setter Property="Shape.Fill"
              TargetName="Arrow"
              Value="#FF8D979E" />
    </Trigger>
    <Trigger Property="UIElement.IsEnabled"
             Value="False">
      <Setter Property="Panel.Background"
              TargetName="Border"
              Value="{StaticResource DisabledBackgroundBrush}" />
      <Setter Property="Border.BorderBrush"
              TargetName="Border"
              Value="{StaticResource DisabledBorderBrush}" />
      <Setter Property="TextElement.Foreground"
              Value="{StaticResource DisabledForegroundBrush}" />
      <Setter Property="Shape.Fill"
              TargetName="Arrow"
              Value="#66FFFFFF" />
    </Trigger>
  </ControlTemplate.Triggers>
</ControlTemplate>

<Style TargetType="{x:Type ComboBox}">
  <Setter Property="Foreground"
          Value="Black" />
  <Setter Property="BorderBrush"
          Value="White" />
  <Setter Property="Background"
          Value="White" />
  <Setter Property="SnapsToDevicePixels"
          Value="true" />
  <Setter Property="OverridesDefaultStyle"
          Value="true" />
  <Setter Property="ScrollViewer.HorizontalScrollBarVisibility"
          Value="Auto" />
  <Setter Property="ScrollViewer.VerticalScrollBarVisibility"
          Value="Auto" />
  <Setter Property="ScrollViewer.CanContentScroll"
          Value="true" />
  <Setter Property="FontFamily"
          Value="Resources/#AGENCYR" />
  <Setter Property="FontSize"
          Value="16" />
  <Setter Property="FontWeight"
          Value="Normal" />
  <Setter Property="HorizontalAlignment"
          Value="Left" />
  <Setter Property="VerticalAlignment"
          Value="Top" />
  <Setter Property="Cursor"
          Value="Arrow" />
  <Setter Property="Height"
          Value="34" />
  <Setter Property="Width"
          Value="387" />
  <Setter Property="MinWidth"
          Value="50" />
  <Setter Property="MinHeight"
          Value="32" />
  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate TargetType="ComboBox">
        <Grid>
          <ToggleButton Name="ToggleButton"
                        BorderBrush="Gray"
                        BorderThickness="0"
                        Background="Gray"
                        Grid.Column="2"
                        Focusable="false"
                        IsChecked="{Binding Path=IsDropDownOpen,Mode=TwoWay,RelativeSource={RelativeSource TemplatedParent}}"
                        ClickMode="Release"
                        Template="{StaticResource ComboBoxToggleButtonTemplate}" />
          <ContentPresenter Name="ContentSite"
                            IsHitTestVisible="False"
                            Content="{TemplateBinding SelectionBoxItem}"
                            ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
                            ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
                            Margin="10,3,30,3"
                            VerticalAlignment="Center"
                            HorizontalAlignment="Center" />
          <Popup Name="Popup"
                 Placement="Bottom"
                 IsOpen="{TemplateBinding IsDropDownOpen}"
                 AllowsTransparency="True"
                 Focusable="False"
                 PopupAnimation="Fade">
            <Grid Name="DropDown"
                  SnapsToDevicePixels="True"
                  MinWidth="{TemplateBinding ActualWidth}"
                  MaxHeight="{TemplateBinding MaxDropDownHeight}">
              <Border x:Name="DropDownBorder"
                      Background="White"
                      BorderThickness="1"
                      BorderBrush="Black" />
              <ScrollViewer Margin="4,6,4,6"
                            SnapsToDevicePixels="True">
                <StackPanel IsItemsHost="True"
                            KeyboardNavigation.DirectionalNavigation="Contained" />
              </ScrollViewer>
            </Grid>
          </Popup>
        </Grid>
        <ControlTemplate.Triggers>
          <Trigger Property="HasItems"
                   Value="false">
            <Setter TargetName="DropDownBorder"
                    Property="MinHeight"
                    Value="95" />
          </Trigger>
          <Trigger Property="IsGrouping"
                   Value="true">
            <Setter Property="ScrollViewer.CanContentScroll"
                    Value="false" />
          </Trigger>
          <Trigger SourceName="Popup"
                   Property="Popup.AllowsTransparency"
                   Value="true">
            <Setter TargetName="DropDownBorder"
                    Property="CornerRadius"
                    Value="0" />
            <Setter TargetName="DropDownBorder"
                    Property="Margin"
                    Value="0,2,0,0" />
          </Trigger>
          <Trigger Property="IsEditable"
                   Value="true">
            <Setter Property="IsTabStop"
                    Value="false" />
            <Setter TargetName="ContentSite"
                    Property="Visibility"
                    Value="Hidden" />
          </Trigger>
        </ControlTemplate.Triggers>
      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>

<Style TargetType="{x:Type ComboBoxItem}">
  <Setter Property="Foreground"
          Value="Black" />
  <Setter Property="Control.Template">
    <Setter.Value>
      <ControlTemplate TargetType="{x:Type ComboBoxItem}">
        <Border Name="Border"
                SnapsToDevicePixels="True"
                Padding="2,2,2,2">
          <ContentPresenter />
        </Border>
        <ControlTemplate.Triggers>
          <Trigger Property="ComboBoxItem.IsHighlighted"
                   Value="True">
            <Setter Property="Panel.Background"
                    TargetName="Border"
                    Value="{StaticResource CustomBrush1}" />
          </Trigger>
          <Trigger Property="UIElement.IsEnabled"
                   Value="False">
            <Setter Property="TextElement.Foreground"
                    Value="{StaticResource DisabledForegroundBrush}" />
          </Trigger>
        </ControlTemplate.Triggers>
      </ControlTemplate>
    </Setter.Value>
  </Setter>
  <Style.Resources>
    <SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" />
    <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" />
  </Style.Resources>
  <Style.Triggers>
    <Trigger Property="IsMouseOver"
             Value="True">
      <Setter Property="Foreground"
              Value="White" />
      <Setter Property="Background"
              Value="#24afb2" />
    </Trigger>
    <Trigger Property="IsSelected"
             Value="True">
      <Setter Property="Background"
              Value="#24afb2" />
      <Setter Property="Foreground"
              Value="White" />
    </Trigger>
    <MultiTrigger>
      <MultiTrigger.Conditions>
        <Condition Property="IsFocused"
                   Value="True" />
        <Condition Property="IsMouseOver"
                   Value="False" />
      </MultiTrigger.Conditions>
      <Setter Property="Foreground"
              Value="White" />
      <Setter Property="Background"
              Value="#24afb2" />
    </MultiTrigger>
    <MultiTrigger>
      <MultiTrigger.Conditions>
        <Condition Property="IsSelected"
                   Value="True" />
        <Condition Property="IsMouseOver"
                   Value="False" />
      </MultiTrigger.Conditions>
      <Setter Property="Foreground"
              Value="Black" />
    </MultiTrigger>
  </Style.Triggers>
</Style>

该样式未定义可编辑ComboBox实例的模板,我认为这可能是您的其他模板尝试执行的操作。也许您可以将其提取到单独的模板,当StyleIsEditable时,您可以通过True设置器设置该模板。

答案 1 :(得分:0)

迈克,我拿着你的模板并用我的文本框嵌入它,但是我在comboBox中得到了箭头,我真的想避免它。但好处是我从组合框模板中删除了文本框,并且能够删除另一个模板....(它显示为已注释)

    <Style x:Key="ComboTextBox" TargetType="{x:Type TextBlock}">
        <Setter Property="IsHitTestVisible" Value="False" />
        <Setter Property="FontFamily" Value="Resources/#AGENCYR" />
        <Setter Property="FontSize" Value="16" />
        <Setter Property="FontWeight" Value="Normal"/>
        <Setter Property="HorizontalAlignment" Value="Left"/>
        <Setter Property="VerticalAlignment" Value="Center" />
        <!--<Setter Property="Foreground" Value="#FFA2C3C4" />-->
        <!--<Setter Property="Foreground" Value="#FF3CEFF4" />-->
        <Setter Property="Foreground" Value="White" />
        <!--<Setter Property="Background" Value="Yellow" />-->
    </Style>

    <ControlTemplate TargetType="TextBox"
             x:Key="ComboBoxTextBoxTemplate">
        <Border Name="PART_ContentHost"
      Background="Gray"
      Focusable="False" />
    </ControlTemplate>

    <ControlTemplate TargetType="ToggleButton"
             x:Key="ComboBoxToggleButtonTemplate">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition Width="16" />
            </Grid.ColumnDefinitions>
            <Border BorderBrush="Gray"
        CornerRadius="2,2,2,2"
        BorderThickness="0,0,0,0"
        Name="Border"
        Background="Gray"
        Grid.ColumnSpan="2" />

            <Path Margin="0,0,3,0"
      Data="M0,0L4,4 8,0z"
      HorizontalAlignment="Center"
      Fill="{StaticResource GlyphBrush}"
      Name="Arrow"
      VerticalAlignment="Center"
      Width="8"
      Grid.Column="1" />
        </Grid>
        <ControlTemplate.Triggers>
            <Trigger Property="UIElement.IsMouseOver"
         Value="True">
                <Setter Property="Panel.Background"
          TargetName="Border"
          Value="Gray" />
            </Trigger>
            <Trigger Property="ToggleButton.IsChecked"
         Value="True">
                <Setter Property="Panel.Background"
          TargetName="Border"
          Value="Gray" />
                <Setter Property="Shape.Fill"
          TargetName="Arrow"
          Value="#FF8D979E" />
            </Trigger>
            <Trigger Property="UIElement.IsEnabled"
         Value="False">
                <Setter Property="Panel.Background"
          TargetName="Border"
          Value="{StaticResource DisabledBackgroundBrush}" />
                <Setter Property="Border.BorderBrush"
          TargetName="Border"
          Value="{StaticResource DisabledBorderBrush}" />
                <Setter Property="TextElement.Foreground"
          Value="{StaticResource DisabledForegroundBrush}" />
                <Setter Property="Shape.Fill"
          TargetName="Arrow"
          Value="#66FFFFFF" />
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <Style TargetType="{x:Type ComboBox}">
        <Setter Property="Foreground"
      Value="#FF3CEFF4" />
        <Setter Property="BorderBrush"
      Value="White" />
        <Setter Property="Background"
      Value="White" />
        <Setter Property="SnapsToDevicePixels"
      Value="true" />
        <Setter Property="OverridesDefaultStyle"
      Value="true" />
        <Setter Property="ScrollViewer.HorizontalScrollBarVisibility"
      Value="Auto" />
        <Setter Property="ScrollViewer.VerticalScrollBarVisibility"
      Value="Auto" />
        <Setter Property="ScrollViewer.CanContentScroll"
      Value="true" />
        <Setter Property="FontFamily"
      Value="Resources/#AGENCYR" />
        <Setter Property="FontSize"
      Value="16" />
        <Setter Property="FontWeight"
      Value="Normal" />
        <Setter Property="HorizontalAlignment"
      Value="Left" />
        <Setter Property="VerticalAlignment"
      Value="Top" />
        <Setter Property="Cursor"
      Value="Arrow" />
        <Setter Property="Height"
      Value="34" />
        <Setter Property="Width"
      Value="387" />
        <Setter Property="MinWidth"
      Value="50" />
        <Setter Property="MinHeight"
      Value="32" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ComboBox">
                    <Grid>
                        <ToggleButton Name="ToggleButton"
                    BorderBrush="Gray"
                    BorderThickness="0"
                    Background="Gray"
                    Grid.Column="2"
                    Focusable="false"
                    IsChecked="{Binding Path=IsDropDownOpen,Mode=TwoWay,RelativeSource={RelativeSource TemplatedParent}}"
                    ClickMode="Release"
                    Template="{StaticResource ComboBoxToggleButtonTemplate}" />
                        <ContentPresenter Name="ContentSite"
                        IsHitTestVisible="False"
                        Content="{TemplateBinding SelectionBoxItem}"
                        ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
                        ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
                        Margin="10,3,30,3"
                        VerticalAlignment="Center"
                        HorizontalAlignment="Left" />
                        <!-- REMOVED THIS ONE TOO <TextBox
            Margin="3,3,23,3"
            Visibility="Hidden"
            HorizontalAlignment="Left"
            Name="PART_EditableTextBox"
            Background="Transparent"
            VerticalAlignment="Left"
            Style="{x:Null}"
            IsReadOnly="False"
            Focusable="True"
            xml:space="preserve"
            Template="{StaticResource ComboBoxTextBoxTemplate}"/>-->
                        <Popup Name="Popup"

             Placement="Bottom"
             IsOpen="{TemplateBinding IsDropDownOpen}"
             AllowsTransparency="True"
             Focusable="False"
             PopupAnimation="Fade">
                            <Grid Name="DropDown"
              SnapsToDevicePixels="True"
              MinWidth="{TemplateBinding ActualWidth}"
              MaxHeight="{TemplateBinding MaxDropDownHeight}">
                                <Border Name="DropDownBorder"
                  Background="White"
                  BorderThickness="1"
                  BorderBrush="Black" />
                                <ScrollViewer Margin="4,6,4,6"
                        SnapsToDevicePixels="True">
                                    <StackPanel IsItemsHost="True"
                        KeyboardNavigation.DirectionalNavigation="Contained" />
                                </ScrollViewer>
                            </Grid>
                        </Popup>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="HasItems"
               Value="false">
                            <Setter TargetName="DropDownBorder"
                Property="MinHeight" Value="95" />
                        </Trigger>
                        <Trigger Property="IsGrouping"
               Value="true">
                            <Setter Property="ScrollViewer.CanContentScroll"
                Value="false" />
                        </Trigger>
                        <Trigger SourceName="Popup"
               Property="Popup.AllowsTransparency"
               Value="true">
                            <Setter TargetName="DropDownBorder"
                Property="CornerRadius"
                Value="0" />
                            <Setter TargetName="DropDownBorder"
                Property="Margin"
                Value="0,2,0,0" />
                        </Trigger>
                        <Trigger Property="IsEditable"
               Value="true">
                            <Setter Property="IsTabStop"
                Value="false" />
                            <Setter TargetName="ContentSite"
                Property="Visibility"
                Value="Hidden" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <!-- FINALLY REMOVED THIS ONE <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ComboBox">
                    <Grid>
                        <ToggleButton
                            Name="ToggleButton"
                            BorderBrush="Gray"
                            BorderThickness="0"
                            Background="Gray"
                            Grid.Column="2"
                            Focusable="false"
                            IsChecked="{Binding Path=IsDropDownOpen,Mode=TwoWay,RelativeSource={RelativeSource TemplatedParent}}"
                            ClickMode="Release">
                        </ToggleButton>
                        <ContentPresenter
                            Name="ContentSite"
                            IsHitTestVisible="False"
                            Content="{TemplateBinding SelectionBoxItem}"
                            ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
                            ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
                            Margin="10,3,30,3"
                            VerticalAlignment="Center"
                            HorizontalAlignment="Left" />
                        <Popup
                            Name="Popup"
                            Placement="Bottom"
                            IsOpen="{TemplateBinding IsDropDownOpen}"
                            AllowsTransparency="True"
                            Focusable="False"
                            PopupAnimation="Fade">
                            <Grid
                                Name="DropDown"
                                SnapsToDevicePixels="True"
                                MinWidth="{TemplateBinding ActualWidth}"
                                MaxHeight="{TemplateBinding MaxDropDownHeight}">
                                <Border
                                x:Name="DropDownBorder"
                                Background="White"
                                BorderThickness="1"
                                BorderBrush="Black"/>
                                <ScrollViewer Margin="4,6,4,6" SnapsToDevicePixels="True">
                                    <StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Contained" />
                                </ScrollViewer>
                            </Grid>
                        </Popup>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="HasItems" Value="false">
                            <Setter TargetName="DropDownBorder" Property="MinHeight" Value="95"/>
                        </Trigger>
                        <Trigger Property="IsGrouping" Value="true">
                            <Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
                        </Trigger>
                        <Trigger SourceName="Popup" Property="Popup.AllowsTransparency" Value="true">
                            <Setter TargetName="DropDownBorder" Property="CornerRadius" Value="0"/>
                            <Setter TargetName="DropDownBorder" Property="Margin" Value="0,2,0,0"/>
                        </Trigger>
                        <Trigger Property="IsEditable" Value="true">
                            <Setter Property="IsTabStop" Value="false"/>
                            <Setter TargetName="ContentSite" Property="Visibility" Value="Hidden"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>-->
    </Style>

    <Style TargetType="{x:Type ComboBoxItem}">
        <Setter Property="Foreground"
      Value="Black" />
        <Setter Property="Control.Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ComboBoxItem}">
                    <Border Name="Border"
            SnapsToDevicePixels="True"
            Padding="2,2,2,2">
                        <ContentPresenter />
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="ComboBoxItem.IsHighlighted"
               Value="True">
                            <Setter Property="Panel.Background"
                TargetName="Border"
                Value="{StaticResource CustomBrush1}" />
                        </Trigger>
                        <Trigger Property="UIElement.IsEnabled"
               Value="False">
                            <Setter Property="TextElement.Foreground"
                Value="{StaticResource DisabledForegroundBrush}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Resources>
            <SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" />
            <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" />
        </Style.Resources>
        <Style.Triggers>
            <Trigger Property="IsMouseOver"
         Value="True">
                <Setter Property="Foreground"
          Value="White" />
                <Setter Property="Background"
          Value="#24afb2" />
            </Trigger>
            <Trigger Property="IsSelected"
         Value="True">
                <Setter Property="Background"
          Value="#24afb2" />
                <Setter Property="Foreground"
          Value="White" />
            </Trigger>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="IsFocused"
               Value="True" />
                    <Condition Property="IsMouseOver"
               Value="False" />
                </MultiTrigger.Conditions>
                <Setter Property="Foreground"
          Value="White" />
                <Setter Property="Background"
          Value="#24afb2" />
            </MultiTrigger>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="IsSelected"
               Value="True" />
                    <Condition Property="IsMouseOver"
               Value="False" />
                </MultiTrigger.Conditions>
                <Setter Property="Foreground"
          Value="Black" />
            </MultiTrigger>
        </Style.Triggers>
    </Style>

现在可以通过将ControlMmplate中的ToogleButton设置为触发器:

来实现
            <Trigger Property="UIElement.IsMouseOver" Value="True">
                <Setter Property="Panel.Background" TargetName="Border"  Value="Gray" />
            </Trigger>
            <Trigger Property="ToggleButton.IsChecked" Value="True">
                <Setter Property="Panel.Background" TargetName="Border" Value="Gray" />
            </Trigger>

使用组合框:

            <!-- The Actual ComboBox -->
            <Grid>
                <ComboBox x:Name="cmbNames" ItemsSource="{Binding SelectedName}" DisplayMemberPath ="FirstName" Width="454">
                </ComboBox>
                <TextBlock x:Name="txtComboBox" Style="{StaticResource ComboTextBox}" 
                           Visibility="{Binding SelectedItem, ElementName=cmbNames, Converter={StaticResource NullToVisibilityConverter}}"
                     Text=" Select ..." />
            </Grid>

希望有人可以看看这个临时解决方案,并为我提供解决方案,解决如何摆脱组合框上的箭头。