1.先在资源类库中编写:style.xaml,如下:

<ResourceDictionary
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
 
  <!-- Background Style -->
  <Style x:Key="styleBackground">
    <Setter Property="Control.Background">
      <Setter.Value>
        <LinearGradientBrush StartPoint="0,0.5" EndPoint="1,0.5" Opacity="0.5">
          <GradientStop Color="LightSkyBlue" Offset="0" />
          <GradientStop Color="WhiteSmoke" Offset="0.5" />
          <GradientStop Color="LightSkyBlue" Offset="1" />
        </LinearGradientBrush>
      </Setter.Value>
    </Setter>
  </Style>
 
  <!-- Banner Style -->
  <Style x:Key="styleBanner">
    <Setter Property="StackPanel.Background">
      <Setter.Value>
        <LinearGradientBrush StartPoint="0,0.25" EndPoint="1,0.5">
          <GradientStop Color="#CC0088DD" Offset="0.3" />
          <GradientStop Color="#3300FFFF" Offset="0.85" />
        </LinearGradientBrush>
      </Setter.Value>
    </Setter>
    <Setter Property="TextBlock.Foreground" Value="Yellow" />
    <Setter Property="TextBlock.FontFamily" Value="Comic Sans MS" />
  </Style>
</ResourceDictionary>
 
2.在App.xaml类中,声明引用类型,
 <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/Resource;component/Styles/Style.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
 </Application.Resources>
 
3.在window、UserControl当中,直接使用动态资源,如下:
<Window  x:Class="SkinnableApp.MainWindow"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"   
  xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"
 
  SizeToContent="Height"
  ResizeMode="NoResize"
  Width="680"
  WindowStartupLocation="CenterScreen"
  WindowStyle="ToolWindow">
  <Grid x:Name="Root" Style="{DynamicResource styleBackground}">
    <!-- BANNER -->
    <Grid Height="70" Style="{DynamicResource styleBanner}" >
      <TextBlock FontSize="26" Padding="10,0,10,0" Text="Insurance Agent Management System" VerticalAlignment="Center"/>
    </Grid>
</Window>

WPF通过DynamicResource的用法的更多相关文章

  1. WPF中StringFormat的用法

    原文:WPF中StringFormat的用法 WPF中StringFormat的用法可以参照C#中string.Format的用法 1. C#中用法: 格式化货币(跟系统的环境有关,中文系统默认格式化 ...

  2. WPF中StringFormat的用法--显示特定位数的数字

    原文:WPF中StringFormat的用法--显示特定位数的数字 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/huangli321456/art ...

  3. 整理:WPF中XmlDataProvider的用法总结

    原文:整理:WPF中XmlDataProvider的用法总结 一.目的:了解XmlDataProvider中绑定数据的方法 二.绑定方式主要有三种: 1.Xaml资源中内置: <!--XPath ...

  4. 整理:WPF中CommandBindings的用法

    原文:整理:WPF中CommandBindings的用法 目的:了解一下CommandBindings.InputBindings.ICommandSource中在WPF中扮演什么样的角色 Comma ...

  5. WPF中log4net的用法

    WPF中如何使用log4nethttp://www.cnblogs.com/C-Sharp2/archive/2013/04/12/WPF-LOG4NET.html Apache log4net Ma ...

  6. WPF 的DynamicResource的NewLine问题

    wpf的TextBlock支持换行,换行可以用 符号来表示. 比如: <TextBlock Text="第1行 第2行"></TextBlock> 显示效果 ...

  7. [WPF系列]-DynamicResource与StaticResource的区别

    探讨: 1.当引用资源时,选择StaticResource还是DynamicResource的考虑因素: (1)在哪里创建资源?(资源的范围或层级) a. 资源是在一个Page/Canvas/Wind ...

  8. WPF通过DynamicResource实现给界面动态更换皮肤

    在我们的程序中有时候需要去实现动态更换皮肤的效果,从而完成一些个性化的设置,那么我们究竟怎样去实现动态换皮肤的效果呢?那么我们经常用到的就是设置不同的Style,并且在主程序的xaml文件中通过Dyn ...

  9. WPF的ComboBox简单用法

    1. ComboBox:下拉列表框 效果如下: 2.通常用法是 显示内容 + 选中内容后获得的值(也就是 Name = Value的键值对) 故以键值对来定义一个类,如: public class C ...

随机推荐

  1. GO调度模型的缺点

    记一次latency问题排查:谈Go的公平调度的缺陷 http://baijiahao.baidu.com/s?id=1587897390639953806&wfr=spider&fo ...

  2. Azure KeyVault设置策略和自动化添加secrets键值对

    一. 关于Azure Key Vault Azure 密钥保管库可帮助保护云应用程序和服务使用的加密密钥和机密. 借助 Key Vault,可使用密钥来加密密钥和机密(例如身份验证密钥.存储帐户密钥. ...

  3. Git中设置代理和取消代理

    设置Socks5代理 git config --global http.proxy 'socks5://127.0.0.1:1080' && git config --global h ...

  4. Windows 服务程序、窗口界面、桌面交互、与远程桌面

    昨天用c写了一个windows服务(服务内部带一个gui窗口+系统托盘),在windows xp sp3上测试,启动服务后,系统托盘显示正常. 但在另一台windows 2003 sp2 上测试(通过 ...

  5. poj 3683(2-SAT+SCC)

    传送门:Problem 3683 https://www.cnblogs.com/violet-acmer/p/9769406.html 参考资料: [1]:挑战程序设计竞赛 题意: 有n场婚礼,每场 ...

  6. mac 中vim永久显示行号、开启语法高亮

    步骤1: cp /usr/share/vim/vimrc ~/.vimrc 先复制一份vim配置模板到个人目录下 注:redhat 改成 cp /etc/vimrc ~/.vimrc 步骤2: vi ...

  7. 【已解决】Microsoft visual c++ 14.0 is required问题解决办法

    装 识别图形验证码库tesserocr的时候,出现了Microsoft visual c++ 14.0 is required的问题,用离线安装还是没有用. 就只能乖乖装Microsoft visua ...

  8. prototype和__proto__区别

    prototype和__proto__分别是显式原型和隐式原型,直接上代码吧: function person(){ this.age = 12; } person.prototype; //Obje ...

  9. 20190311 Windows安装ZooKeeper

    1. 说明 记录过程中踩过的坑 1.1. 环境 本机环境:Win10 ZooKeeper版本:3.4.6 2. 安装 2.1. 下载 官网下载网址 2.2. 修改配置文件 复制conf目录下的zoo_ ...

  10. JVM调优命令-jstack

    jstack jstack用于生成java虚拟机当前时刻的线程快照.线程快照是当前java虚拟机内每一条线程正在执行的方法堆栈的集合,生成线程快照的主要目的是定位线程出现长时间停顿的原因,如线程间死锁 ...