个人WPF快速入门笔记 - 基础样式篇02
生命 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>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库