How do I get a white WPF ComboBox DropDown arrow c

2019-08-12 13:38发布

问题:

I am trying to work out a style for a ComboBox that has a navy background with white text, so I want the drop down arrow to be white also (the xaml I have so far is below).

  <Style x:Key="ComboBoxStyle" TargetType="ComboBox">
     <Setter Property="Background" Value="{StaticResource headerBrush}"/>
     <Setter Property="Foreground" Value="White"/>
     <Setter Property="BorderBrush" Value="{StaticResource headerBorderBrush}"/>
     <Setter Property="BorderThickness" Value="1"/>
     <Setter Property="SnapsToDevicePixels" Value="True"/>
     <Setter Property="MinWidth" Value="100"/>
     <Setter Property="Height" Value="21"/>
     <Setter Property="Cursor" Value="Hand"/>
     <Setter Property="Padding" Value="5"/>
     <Setter Property="Margin" Value="3"/>
     <Setter Property="HorizontalContentAlignment" Value="Center"/>
  </Style>
  <Style x:Key="ComboBoxItemStyle" TargetType="ComboBoxItem">
     <Setter Property="Background" Value="AliceBlue"/>
     <Setter Property="Foreground" Value="Navy"/>
     <Setter Property="HorizontalContentAlignment" Value="Left"/>
  </Style>

ADDED code to set the ControlTemplate?

<Setter Property="Template">
    <Setter.Value>
        <ControlTemplate TargetType="ComboBox">
            <Path x:Name="Arrow" Fill="White"/>
        </ControlTemplate>
    </Setter.Value>
</Setter>

回答1:

You need to edit the ControlTemplate of ComboBox and you can see a the Arrow as a Path. So change the Fill property of the Path to your desired arrow color. See sample ControlTemplate here http://msdn.microsoft.com/en-us/library/ms752094.aspx