【问题标题】:How do I get a white WPF ComboBox DropDown arrow color?如何获得白色的 WPF ComboBox DropDown 箭头颜色?
【发布时间】:2010-12-14 12:30:38
【问题描述】:

我正在尝试为 ComboBox 设计一种样式,该样式具有海军背景和白色文本,因此我希望下拉箭头也为白色(我目前拥有的 xaml 如下)。

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

添加了设置ControlTemplate的代码?

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

【问题讨论】:

    标签: wpf combobox styles drop-down-menu


    【解决方案1】:

    您需要编辑 ComboBox 的 ControlTemplate,您可以看到箭头作为路径。因此,将 Path 的 Fill 属性更改为所需的箭头颜色。在此处查看示例 ControlTemplate http://msdn.microsoft.com/en-us/library/ms752094.aspx

    【讨论】:

    • 我猜我还没有真正得到 ControlTemplates。该示例中的目标类型是 ToggleButton,这让我在 xaml 设计器中遇到了异常。将其更改为 ComboBox 似乎已将整个控件变为白色。我可以做一些简单的事情来解决这个问题(请参阅编辑的代码)?谢谢
    • 如果您有 Expression Blend,只需右键单击并选择编辑模板 -> 编辑副本(我认为这些名称是正确的)。否则,您应该将 Reflector 与 BamlViewer 加载项一起使用,以从 PresentationFramework.Aero.dll 中获取 XAML,并剪掉您需要的部分。
    • 您编辑的模板的问题是它没有 ComboBox 的所有其他功能。当您查看 Microsoft 提供的模板时,您会发现它相当复杂。复制他们的代码并进行所需的更改。
    猜你喜欢
    • 2021-05-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-07
    • 2013-08-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多