更改组合框样式和颜色

时间:2014-03-17 12:22:51

标签: c# wpf xaml

我有一个combobox,我想改变它的风格和颜色。应该变成白色而不是灰色。我该怎么做?

我尝试使用OpacityMask = "White",这对我不起作用..

4 个答案:

答案 0 :(得分:1)

对于WPF,

var combo = new Combobox(); 
combo.Background = Brushes.White;
combo.Foreground = Brushes.Black;

您想要检查样式触发器。

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

答案 1 :(得分:1)

此样式将应用于所有组合框。

<Style x:Key="{x:Type ComboBox}" TargetType="{x:Type ComboBox}">
<Setter Property="Background" Value="White" /> 
</Style>

如果您想使用特定的组合框:

<Style x:Key="ComboStyle" TargetType="{x:Type ComboBox}">
 <Setter Property="Background" Value="White" /> 
</Style>

要获得完整的模板检查MSDN

答案 2 :(得分:0)

使用BackgroundColor属性设置该控件的颜色。

答案 3 :(得分:0)

使用以下示例

  <Style TargetType="ComboBox">

            <Setter Property="ComboBox.BorderBrush"
                    Value="LightSlateGray" />
            <Setter Property="ComboBox.Background"
                    Value="white" />
            <Style.Triggers>
相关问题