生命 Window.Resources 样式定义
子节点Style
属性 TargetType 指定应用该样式的控件类型(如:Button)
属性:x:Key 定义样式的名字
属性:BaseOn 可以集成其他的style样式
字节点 Setter
属性 Property 值指定样式属性
属性Value 值 指定样式属性值
具体控件使用方式:
Style="{StaticResource 样式style名}"
小节示例Demo:
<Window x:Class="WpfApp1.example1" 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:WpfApp1" mc:Ignorable="d" Title="example1" Height="450" Width="800"> <Window.Resources> <Style x:Key="btn1" TargetType="Button"> <Setter Property="FontSize" Value="25"/> <Setter Property="Background" Value="Pink"/> </Style> </Window.Resources> <Grid> <Grid.RowDefinitions> <RowDefinition Height="80px" /> <RowDefinition Height="100px"/> <RowDefinition/> </Grid.RowDefinitions> <Border Background="#66ccff" /> <TextBlock FontSize="25px" TextAlignment="Center" VerticalAlignment="Center" Text="洛天依天钿智能数据平台" Foreground="#fff" /> <Grid Grid.Row="1"> <Grid.ColumnDefinitions> <ColumnDefinition/> <ColumnDefinition/> <ColumnDefinition/> <ColumnDefinition/> <ColumnDefinition/> <ColumnDefinition/> </Grid.ColumnDefinitions> <Button Margin="5" Grid.Row="0" Grid.Column="0" Style="{StaticResource btn1}" TextBlock.Foreground="#fff">手动导入</Button> <Button Margin="5" Grid.Row="0" Grid.Column="1" Style="{StaticResource btn1}" TextBlock.Foreground="Green">开启线程</Button> <Button Margin="5" Grid.Row="0" Grid.Column="2" Style="{StaticResource btn1}" TextBlock.Foreground="red">关闭所有</Button> <Button Margin="5" Grid.Row="0" Grid.Column="3" Style="{StaticResource btn1}" TextBlock.Foreground="#fff">同步站点</Button> <Button Margin="5" Grid.Row="0" Grid.Column="4" Style="{StaticResource btn1}" TextBlock.Foreground="#fff">数据通知</Button> <Button Margin="5" Grid.Row="0" Grid.Column="5" Style="{StaticResource btn1}" TextBlock.Foreground="#fff">日志查询</Button> </Grid> </Grid> </Window>