新建资源文件

 

写资源文件

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfDemo.Style">
<Style TargetType="Button" x:Key="MyStyleButton">
<Setter Property="Background" Value="Pink"></Setter>
</Style>
</ResourceDictionary>

引用资源

在独立的窗口/用户控件中引用

<Window x:Class="WpfDemo.Style.UseResourceDictionaryDemo"
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:WpfDemo.Style"
mc:Ignorable="d"
Title="UseResourceDictionaryDemo" Height="300" Width="300">
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="MyStyle.xaml"></ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<Grid>
<Button Style="{StaticResource MyStyleButton}"></Button>
</Grid>
</Window>

在App.xaml中统一引用(全局引用)

<!--App.xaml(WPF原生默认style.xaml,不同框架有所不同)-->
<Application x:Class="MAS.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Style/MyStyle.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>

小结

写法和写在Resources中一样,只是多了个ResourceDictionary的文件,并需要引用ResourceDictionary文件才能使用Style

示例代码

https://github.com/zLulus/NotePractice/tree/dev3/WPF/WpfDemo/Style 下的MyStyle和UseResourceDictionaryDemo

style文件的指定的更多相关文章

  1. ArcGIS Engine Style文件操作

    对于一个GISer来说,地图,符号这些都应该有着比别人更深刻的理解和认识,作为平台软件都会提供一套自己的符号库,符号库里面根据类别和种类进行区分,因为点,线,面的自然存在和固有属性是不肯能让你用面状符 ...

  2. WPF 中style文件的引用

    原文:WPF 中style文件的引用 总结一下WPF中Style样式的引用方法: 一,内联样式: 直接设置控件的Height.Width.Foreground.HorizontalAlignment. ...

  3. [工具] Firemonkey Style 调色工具(可另存 Style 文件)

    版本:2016.12.21 (新增可取代颜色) 下载:[工具]OneStylePalette_调色工具_20161221.zip 版本:2016.12.09 (新增可导出全平台的 Style) 下载: ...

  4. Linux tar (打包.压缩.解压缩)命令说明 | tar如何解压文件到指定的目录?

    打包举例:将 /usr/local/src/zlib-1.2.5目录下的文件打包成 zlib-1.2.5.tar.gz cd /usr/local/src tar -czvf ./zlib-1.2.5 ...

  5. linux tar 解压文件时指定文件名

      linux解压文件时指定文件夹名称   wget -O mysql-5.6.15.tar.gz  http://oss.aliyuncs.com/aliyunecs/onekey/mysql/my ...

  6. Oracle RMAN 恢复控制文件到指定的路径

    Oracle 数据库通过RMAN恢复控制文件到指定的路径 --------------------------------------------------------- 先查询备份集信息,再指定备 ...

  7. [自动运维]ant脚本打包,上传文件到指定服务器,并部署

    1.根节点使用,表示根目录为当前目录,默认启动的target为build,项目名称为othersysm, <project basedir="." default=" ...

  8. C#项目打开/保存文件夹/指定类型文件,获取路径

    C#项目打开/保存文件夹/指定类型文件,获取路径 转:http://q1q2q363.xiaoxiang.blog.163.com/blog/static/1106963682011722424325 ...

  9. shell如何在指定文件的指定位置后面添加内容

    最近工作中遇到一个问题,想在某个文件的指定位置后面添加一个标志位,要求在shell脚本里实现. 问题说明: 想在sys_config.fex文本的某个字符串后面添加一个flag 例如:sys_conf ...

随机推荐

  1. spring(3)------控制反转(IOC)/依赖注入(DI)

    一.spring核心概念理解 控制反转: 控制反转即IoC (Inversion of Control).它把传统上由程序代码直接操控的对象的调用权交给容器.通过容器来实现对象组件的装配和管理. 所谓 ...

  2. Windows Server 2012 R2 部署 Exchange 2013

    我的环境在DC上 ,一般建议Exchange 增加DC 通过管理员权限执行PowerShell 来安装一些IIS组件, 安装命令例如以下: Install-WindowsFeature AS-HTTP ...

  3. Fragment之一:Fragment入门 分类: H1_ANDROID 2013-11-15 18:16 2799人阅读 评论(2) 收藏

    参考自张泽华视频 Fragment是自Android3.0后引入的特性,主要用于在不同的屏幕尺寸中展现不同的内容. Fragment必须被嵌入Activity中使用,总是作为Activity的组成部分 ...

  4. php求二叉树的深度(1、二叉树就可以递归,因为结构和子结构太相似)(2、谋而后动,算法想清楚,很好过的)

    php求二叉树的深度(1.二叉树就可以递归,因为结构和子结构太相似)(2.谋而后动,算法想清楚,很好过的) 一.总结 1.二叉树就可以递归,因为结构和子结构太相似 2.谋而后动,算法想清楚,很好过的 ...

  5. JQuery中Ajax详细参数使用案例

    JQuery中Ajax详细参数使用案例 参考文档:http://www.jb51.net/shouce/jquery1.82/ 参考文档:http://jquery.cuishifeng.cn/jQu ...

  6. Android 用MediaRecorder录制视频太短崩的问题

    具体表现: 调用MediaRecorder的start()与stop()间隔不能小于1秒(有时候大于1秒也崩),否则必崩. 错误信息: java.lang.RuntimeException: stop ...

  7. 删除vector中的重复数据(unique)

    #include <iostream> #include <vector> #include <algorithm> #include <assert.h&g ...

  8. [Angular] Pipes as providers

    In this example, we are going to see how to use Pipe as providers inject into component. We have the ...

  9. mysql创建应用账号

    -- 赋予某个库全部权限use mysql;grant all privileges on test_db.* to test_user@'%' identified by 'Aa123456';gr ...

  10. 使用SecureCRT连接AWS的EC2

    如果使用CentOS等linux系统,直接使用ssh命令即可访问AWS上的Linux-EC2实例. $ ssh -i XXX.pem ec2-user@{IP/hostname} 在Windows系统 ...