SolidColorBrush
单色画刷,Color属性设置其颜色
<Window x:Class="画刷.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:画刷"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded">
<StackPanel>
<Button Name="button1" Width="100" Content="Button" VerticalAlignment="Top" Height="65" Margin="10,10,0,0" HorizontalAlignment="Left" >
<Button.Background>
<SolidColorBrush Color="LightBlue"></SolidColorBrush>
</Button.Background>
</Button>
</StackPanel>
</Window>
通过此设置将button按钮的背景色进行设置 <Button.Background> <SolidColorBrush Color="LightBlue"></SolidColorBrush> </Button.Background>
在窗口加载时通过SolidColorBrush画刷修改button前景色
private void Window_Loaded(object sender, RoutedEventArgs e)
{
this.button1.Foreground = new SolidColorBrush(Colors.Red);
}
运行后得到如下结果: