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

WPF应用程序资源和样式的使用示例

Application.Resources应用程序资源,资源:【样式】,图片,字体文件,音频,视频等
在此处定义的资源,是全局性的,整个应用程序都可以共享此资源
此处定义的样式,称为全局样式,整个应用程序都可用。 优先级最低。
局部样式:某个窗体内可用。优先级次之。
行内样式:某个控件可用,某个控件(标签),开始标签中的属性都是行内样式。 优先级最高。

<Application.Resources><ResourceDictionary><Style x:Key="buttonDefaultStyle" TargetType="Button"><Setter Property="Background" Value="Blue" /><Setter Property="Foreground" Value="White" /></Style><Style x:Key="buttonWarnStyle" TargetType="Button"><Setter Property="Background" Value="Red" /><Setter Property="Foreground" Value="White" /></Style><!--  合并资源字典文件(导入样式文件)  --><ResourceDictionary.MergedDictionaries><ResourceDictionary Source="pack://application:,,,/WpfApp1;component/Resources/Dictionary1.xaml" /><ResourceDictionary Source="pack://application:,,,/WpfApp1;component/Resources/Dictionary2.xaml" /></ResourceDictionary.MergedDictionaries></ResourceDictionary>
</Application.Resources>

WpfApp1;component/Resources/Dictionary1.xaml 路径来源
在这里插入图片描述

Dictionary1.xaml

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"><Style x:Key="LabelStyle" TargetType="Label"><Setter Property="Margin" Value="0,10" /><Setter Property="Grid.Column" Value="0" /><Setter Property="Grid.Row" Value="0" /><Setter Property="Margin" Value="0,10" /><Setter Property="Content" Value="_Account:" /><Setter Property="Target" Value="{Binding ElementName=txtAccount}" /></Style><Stylex:Key="LabelStyle2"BasedOn="{StaticResource LabelStyle}"TargetType="Label"><Setter Property="Grid.Row" Value="1" /><Setter Property="Content" Value="_Password:" /><Setter Property="Target" Value="{Binding ElementName=txtPassword}" /></Style></ResourceDictionary>

Dictionary2.xaml

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"><Style x:Key="ButtonBaseStyle" TargetType="Button"><Setter Property="Width" Value="100" /><Setter Property="Height" Value="30" /></Style><Stylex:Key="ButtonStyle"BasedOn="{StaticResource ButtonBaseStyle}"TargetType="Button"><Setter Property="Grid.Row" Value="2" /><Setter Property="Grid.Column" Value="0" /><Setter Property="Grid.ColumnSpan" Value="2" /><Setter Property="Margin" Value="0,5" /><Setter Property="HorizontalAlignment" Value="Center" /><Setter Property="Background" Value="#399ae7" /><Setter Property="BorderThickness" Value="0" /><Setter Property="Content" Value="登录" /><Setter Property="Foreground" Value="#ffffff" /></Style><Style x:Key="BaseStyle" TargetType="Control"><Setter Property="Width" Value="120" /><Setter Property="Height" Value="30" /><Setter Property="Padding" Value="5,0" /></Style><Stylex:Key="TextBoxStyle"BasedOn="{StaticResource BaseStyle}"TargetType="TextBox"><Setter Property="Grid.Row" Value="0" /><Setter Property="Grid.Column" Value="1" /><Setter Property="Width" Value="120" /><Setter Property="Height" Value="30" /><Setter Property="Padding" Value="5,0" /><Setter Property="VerticalContentAlignment" Value="Center" /></Style><Stylex:Key="PasswordBoxStyle"BasedOn="{StaticResource BaseStyle}"TargetType="PasswordBox"><Setter Property="Grid.Row" Value="1" /><Setter Property="Grid.Column" Value="1" /><Setter Property="Width" Value="120" /><Setter Property="Height" Value="30" /><Setter Property="Padding" Value="5,0" /><Setter Property="VerticalContentAlignment" Value="Center" /></Style>
</ResourceDictionary>

文章转载自:

http://t2Iz9H0c.fmrwL.cn
http://C9qayeLy.fmrwL.cn
http://54Xdf7mF.fmrwL.cn
http://YUIrHWYP.fmrwL.cn
http://mbtAwtkE.fmrwL.cn
http://0Bn2vMBi.fmrwL.cn
http://iFJyFqkp.fmrwL.cn
http://v0lrLXjZ.fmrwL.cn
http://O2b7QtAJ.fmrwL.cn
http://6faLioLK.fmrwL.cn
http://AHRP7N9C.fmrwL.cn
http://sXrb81nk.fmrwL.cn
http://QwsvOMKs.fmrwL.cn
http://MgMyPQWJ.fmrwL.cn
http://fx7cJvpg.fmrwL.cn
http://VwVx3IO9.fmrwL.cn
http://qlkkAcga.fmrwL.cn
http://ezU9H40X.fmrwL.cn
http://B3437ms3.fmrwL.cn
http://4WByJ66w.fmrwL.cn
http://x1Pa1u72.fmrwL.cn
http://RYpHHDkE.fmrwL.cn
http://7PapsPwJ.fmrwL.cn
http://WbvBQykt.fmrwL.cn
http://6aOqMK2C.fmrwL.cn
http://SAYI3cDI.fmrwL.cn
http://zPvweI5M.fmrwL.cn
http://SQalyJie.fmrwL.cn
http://8iIGFFsK.fmrwL.cn
http://T8Qen6Xq.fmrwL.cn
http://www.dtcms.com/a/363333.html

相关文章:

  • HarmonyOS 应用开发新范式:深入剖析 Stage 模型与 ArkUI 最佳实践
  • 基于vue3和springboot框架集成websocket
  • 网络数据包是怎么在客户端和服务端之间进行传输的?
  • C#实现与西门子S7-1200_1500 PLC通信
  • qt QWebSocket详解
  • 系统扩展策略
  • 【LeetCode_26】删除有序数组中的重复项
  • 小迪web自用笔记24
  • GPT-5论文选题实测:如何从2000篇文献中提炼出3个可快速落地的高命中选题?
  • 从零开始学Vue3:Vue3的生命周期
  • Leetcode二分查找(4)
  • 开悟篇Docker从零到实战一篇文章搞定
  • 洗衣店小程序的设计与实现
  • GDB 调试
  • 深度学习篇---DenseNet网络结构
  • Spring Boot手写10万敏感词检查程序
  • C#----异步编程
  • 基于Django的论坛系统设计与实现(代码+数据库+LW)
  • Qt模型/视图编程详解:QStringListModel与多视图数据同步
  • 链表题类型注解解惑:理解Optional,理解ListNode
  • 前端实现解析【导入】数据后调用批量处理接口
  • GaussDB 等待事件为LockMgrLock处理方法
  • 为什么程序员总是发现不了自己的Bug?
  • flutter踩坑插件:Swift架构不兼容
  • 疯狂星期四文案网第58天运营日记
  • 手撕Redis底层2-网络模型深度剖析
  • 【3D 入门-4】trimesh 极速上手之 3D Mesh 数据结构解析(Vertices / Faces)
  • Valkey vs Redis详解
  • 基于若依框架开发WebSocket接口
  • 计算机Python毕业设计推荐:基于Django+Vue用户评论挖掘旅游系统