当前位置: 首页 > news >正文

WPF之Style

样式分为静态样式和动态样式

静态样式【StaticResource 】:编译后就不能修改样式了

动态样式【DynamicResource 】:编译后可以修改样式,可以用于主题切换设置

实例效果:

对应的xmal代码:

<Window x:Class="Wpf_Style.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:Wpf_Style"mc:Ignorable="d"Title="MainWindow" Height="450" Width="800"><Window.Resources><!--定义一个样式基类--><Style  TargetType="Button"><Setter Property="Background" Value="Blue"/><Setter Property="FontSize" Value="30"/><Setter Property="Height" Value="50"/><Setter Property="Width" Value="200"/><Setter Property="Margin" Value="20,10"/></Style><!--继承基类样式后,拓展新样式--><Style x:Key="login_style" TargetType="Button" BasedOn="{StaticResource {x:Type Button}}"><Setter Property="Background" Value="green"/></Style><!--继承基类样式后,拓展新样式--><Style x:Key="quit_style" TargetType="Button" BasedOn="{StaticResource {x:Type Button}}"><Setter Property="Background" Value="Red"/></Style></Window.Resources><StackPanel><Button  Style="{StaticResource login_style}"  Content="登录"  /><Button Style="{StaticResource quit_style}"  Content="退出" /><Button Content="忘记密码"/></StackPanel>
</Window>

http://www.dtcms.com/a/528243.html

相关文章:

  • zabbix实现监控Apache、Nginx、php-fpm应用的实操保姆级流程
  • 69.力扣LeetCode_x的平方根
  • linux第二次作业
  • (二)Gradle 依赖仓库及安全凭证配置
  • 医疗信创标杆实践:浙人医 LIS 系统异构多活容灾架构深度解析(附 KingbaseES 实战)
  • 廊坊怎么做网站免费访问国外网站的应用
  • 对网站建设好学吗vps 需刷新几次才能打开网站
  • 百日挑战之单词篇(第三天)
  • 【C++】list 常见使用和模拟实现
  • HTML HTML5基础(2)
  • macOS安装使用Oh My Tmux教程
  • SpringBoot+FFmpeg+ZLMediaKit 实现本地视频推流
  • Mac-终端
  • 中科大分子生物学Ⅲ复习题2025年
  • 关于lvgl-for linxu的dockerfile
  • 做ppt的网站叫什么名字sem和seo是什么职位
  • 临沂网站建设有哪些公司网页制作模板
  • UDP多线程在线咨询
  • 微信小程序原生如何使用画布生成名片
  • Postman介绍和安装,发送带参数的GET请求
  • 海西州wap网站建设公司网站布局怎么用dw做
  • Python入门经典题目
  • 佛山网站建设乐云seo在线制作wordpress媒体库略缩图
  • 网站的服务器怎么做的网站模板软件
  • Go Web 编程快速入门 07.4 - 模板(4):组合模板与逻辑控制
  • 【Canvas与旗帜】标准加拿大枫叶旗
  • LwIP协议栈MPA多进程架构
  • 【JUnit实战3_12】第七章:用 Stub 模拟进行粗粒度测试
  • 东莞网络推广网站做静态网站软件
  • 想建网站做优化网站建设服务费 印花税