所有控件都包含背景和前景属性,设置Background和Foreground的值改变背景或前景颜色。

1.使用代码设置颜色

            button1.Background = new SolidColorBrush(Colors.Blue);

button2.Background = new SolidColorBrush(SystemColors.ControlColor);
//button2.Background = SystemColors.ControlBrush;
//button2.Background = new SolidColorBrush(Color.FromRgb(0,255,0));

2.XAML中设置颜色

    <Grid>
<Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="59,12,0,0" Name="button1" VerticalAlignment="Top" Width="75" />
<Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="156,12,0,0" Name="button2" VerticalAlignment="Top" Width="75" />
<Button Content="Button" Background="Red" Height="23" HorizontalAlignment="Left" Margin="59,68,0,0" Name="button3" VerticalAlignment="Top" Width="75" />
<Button Content="Button" Height="23" HorizontalAlignment="Right" Margin="0,68,107,0" Name="button4" VerticalAlignment="Top" Width="75" Click="button4_Click">
<Button.Background>
<SolidColorBrush Color="Blue"/>
</Button.Background>
</Button>
</Grid>

 



相关文章:

  • 2021-10-31
  • 2022-12-23
  • 2022-12-23
  • 2021-10-02
  • 2021-07-27
  • 2021-07-06
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-05-25
  • 2022-12-23
  • 2021-10-25
  • 2021-08-08
  • 2021-10-25
  • 2022-12-23
相关资源
相似解决方案