【WPF】二、样式基础
<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>
本文作者:xxxyz
本文链接:https://www.cnblogs.com/xxxyz/p/16629411.html
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步