<Window x:Class="WpfApp1.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:WpfApp1"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Window.Resources>
<!--这是基础的模板其他控件可以引用-->
<Style x:Key="BaseText" TargetType="TextBox" >
<Setter Property="FontSize" Value="18"></Setter>
<Setter Property="Foreground" Value="White"></Setter>
<Setter Property="Background" Value="LightBlue"></Setter>
</Style>
<!--这是引用后的控件-->
<Style x:Key="inputText" TargetType="TextBox" BasedOn="{StaticResource BaseText}">
<Setter Property="Text" Value="请输入身份证号"></Setter>
</Style>
<!--这是一个button控件样式-->
<Style x:Key="clickButton" TargetType="Button">
<Setter Property="FontSize" Value="18"></Setter>
<Setter Property="Content" Value="查询"></Setter>
<Setter Property="Foreground" Value="White"></Setter>
<Setter Property="Background" Value="Orange"></Setter>
</Style>
</Window.Resources>
<Grid>
<StackPanel>
<Label>33</Label>
<!--控件样式实现方式-->
<TextBox Style="{StaticResource inputText}"></TextBox>
<Button Style="{StaticResource clickButton}"></Button>
</StackPanel>
</Grid>
</Window>
标签:样式,33,WPF,基础 From: https://www.cnblogs.com/xxxyz/p/16629411.html