WPF combobox colors

浪尽此生 提交于 2019-12-23 04:58:09

问题


I'm changing the look of all ComboBoxes in my application by adding this Style to App.xaml:

    <Style TargetType="ComboBox">
        <Setter Property="Foreground" Value="White"/>
        <Setter Property="Background" Value="#303030"/>
        <Setter Property="BorderBrush" Value="#000000"/>
    </Style>

There are two colors that I haven't been able to set:

1) the Background color whenIsEnabled=false

2) the highlight Background color when the mouse is over the ComboBox.

How can I change these two colors?

[edit: it looks like the highlight color is not the same as the mouse over color, because when I move my mouse over the ComboBox it will briefly turn the color I defined as the mouse over color, and then turn into some other color (light blue)]


回答1:


You want to check Style Triggers . Also need to override the ItemContainerStyle to get rid of the default light blue selection color

<Style.Triggers>
  <Trigger Property="IsMouseOver" Value="true">
    <Setter Property="Background" Value="SomeColor" />
  </Trigger>
  <Trigger Property="IsEnabled" Value="false">
    <Setter Property="Background" Value="SomeOtherColor" />
  </Trigger>
</Style.Triggers>


来源:https://stackoverflow.com/questions/2385205/wpf-combobox-colors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!