当前位置: 首页 > 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://www.xdnf.cn/news/1430335.html

相关文章:

  • 洗衣店小程序的设计与实现
  • 深度学习篇---DenseNet网络结构
  • gitlab中回退代码,CI / CD 联系运维同事处理
  • VR森林经营模拟体验带动旅游经济发展
  • Time-MOE 音频序列分类任务
  • 【C++框架#2】gflags 和 gtest 安装使用
  • Redis 的跳跃表:像商场多层导航系统一样的有序结构
  • 疯狂星期四文案网第58天运营日记
  • 大模型微调数据准备全指南:清洗、标注与高质量训练集构造实战
  • 科研界“外挂”诞生了:科学多模态模型Intern-S1-mini开源
  • 我的项目我做主:Focalboard+cpolar让团队协作摆脱平台依赖
  • 大数据毕业设计选题推荐-基于大数据的电脑硬件数据分析系统-Hadoop-Spark-数据可视化-BigData
  • 临时邮箱地址获取服务器邮件工作流程与实现
  • playwright+python 实现图片对比
  • 【代码里的英雄传】Dubbo 的一生:一位分布式勇士的传奇旅程
  • 依托深兰科技AI技术生态,深兰教育携手沪上高校企业启动就业科创营
  • 高性能接口实现方案
  • 【微服务】-Gson反序列化泛型类型踩坑指南:如何正确处理Result<T>类型
  • MTK Linux DRM分析(三十)- MTK mtk_dsi.c(Part.2)
  • AI零售创业公司:零眸智能
  • PHP操作LibreOffice将替换变量后的word文件转换为PDF文件
  • ffmpeg 安装
  • C#基础(⑤ProcessStartInfo类和Process类)
  • Centos10虚拟机安装Zabbix
  • 面试tips--MySQLRedis--Redis 有序集合用跳表不用B+树 MySQL用B+树作为存储引擎不用跳表:原因如下
  • 卫朋:基于IPD思维的产品规划逻辑
  • Android Binder 驱动 - Media 服务启动流程
  • 三格电子CAN总线通信原理及在消防领域中的应用
  • 第三章:生活重构:当程序员不再只是“码农“
  • 威科夫与强化学习状态