“Sometimes it's useful to use one of the selected colors or fonts the user has chosen in the
Windows Control Panel Personalization applet (or the older Display Settings in Windows XP),
such as Window caption, Desktop color, and Selection color. Furthermore, an application
may want to react dynamically to changes in those values. This can be achieved by accessing
special resource keys within the SystemColors and SystemFonts classes.”

有时候,我们想要使用用户在控制面板中选择的主题的颜色,或是我们希望我们的程序能够跟着用户选择不同的主题,变换相应的颜色。这时候我们可以通过访问SystemColors和SystemFonts类的特定的Resource keys。

Code Snip如下:

<Window x:Class="UsingUserSelectedColorsAndFonts.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<StackPanel >
<TextBlock Text="Hello from Active Caption Font" FontFamily="{ DynamicResource {x:Static SystemFonts.CaptionFontFamilyKey}}" FontSize="{ DynamicResource {x:Static SystemFonts.CaptionFontSizeKey}}"/>
<Rectangle Height="100" Stroke="DarkViolet" StrokeThickness="10" Fill="{DynamicResource {x:Static SystemColors.DesktopBrushKey}}"/>
</StackPanel>
</Window>

注意这个,和前面的WPF整理-XAML访问静态属性 的对比:

"XAML provides an easy way to set values of properties—type converters and the extended property syntax allow for flexible setting of values. However, some things cannot be expressed as a simple value, such as setting a property to the value of some static property."

这个相对比较简单,知道就行,Code Snip如下:

    <StackPanel>
<Ellipse Stroke="Black" Height="50" Fill="{x:Static SystemColors.DesktopBrush}"/>
<Rectangle Stroke="Black" Height="50" Fill="{x:Static SystemColors.ActiveCaptionBrush}"/>
</StackPanel>

两者采用不同的方法实现相同的效果。

对比如下:

    <StackPanel >
<TextBlock Text="Hello from Active Caption Font" FontFamily="{ DynamicResource {x:Static SystemFonts.CaptionFontFamilyKey}}" FontSize="{ DynamicResource {x:Static SystemFonts.CaptionFontSizeKey}}"/>
<Rectangle Height="100" Stroke="DarkViolet" StrokeThickness="10" Fill="{DynamicResource {x:Static SystemColors.DesktopBrushKey}}"/>
<StackPanel>
<TextBlock Text="Hello from Active Caption Font" FontFamily="{ x:Static SystemFonts.CaptionFontFamily}" FontSize="{ x:Static SystemFonts.CaptionFontSize}"/>
<Rectangle Height="100" Stroke="DarkViolet" StrokeThickness="10" Fill="{x:Static SystemColors.DesktopBrush}"/>
</StackPanel>
</StackPanel>

效果如下:

如果我们改变系统地主题:

再次编译运行,则程序运行如下:

看不出区别~

但,若我们程序保持运行,改变主题,则程序界面随之改变如下:

这就是两者的区别。

WPF整理-使用用户选择主题的颜色和字体的更多相关文章

  1. WPF整理-XAML访问静态属性

    "XAML provides an easy way to set values of properties—type converters and the extended propert ...

  2. css整理-02 颜色和字体

    颜色 命名颜色 RGB指定颜色 数值: 0-255 百分比 三元组:红绿蓝 16进制RGB web安全颜色 在256色计算机系统上总能避免抖动的颜色 表示为rgb值20%和51的倍数 web安全色的简 ...

  3. Node.js:实现知乎(www.zhihu.com)模拟登陆,获取用户关注主题

    前一段时间,在瞎看看 Node.js,便研究通过 Node.js 实现知乎模拟登陆.相信,有很多网站有登陆权限设置,如若用户未登陆,将会跳转至首页提醒用户登陆,无法浏览部分页面. 如若是 b/s 架构 ...

  4. WPF 精修篇 用户控件

    原文:WPF 精修篇 用户控件 增加用户控件 数据绑定还是用依赖属性 使用的事件 就委托注册一下 public delegate void ButtonClick(object b,EventArgs ...

  5. WPF整理-Style

    "Consistency in a user interface is an important trait; there are many facets of consistency,   ...

  6. WPF整理-自定义一个扩展标记(custom markup extension)

    "Markup extensions are used to extend the capabilities of XAML, by providing declarativeoperati ...

  7. WPF整理-XAML构建后台类对象

    1.XAML 接触WPF的第一眼就是XAML---XAML是用来描绘界面的.其实不然! "Actually, XAML has nothing to do with UI. It's mer ...

  8. Winform开发框架之权限管理系统改进的经验总结(2)-用户选择界面的设计

    在上篇总结随笔<Winform开发框架之权限管理系统改进的经验总结(1)-TreeListLookupEdit控件的使用>介绍了权限管理模块的用户管理部分,其中主要介绍了其中的用户所属公司 ...

  9. 从a站点跳转到b站点,通过url的参数判断是否让该用户选择身份

    一.问题的由来 问题是这样子给出来,今天产品那边跟我说,在a网站跳转到b网站时,让用户有一个选择身份的弹窗.因为公司有两个不同站点,你无论在a或者b网站注册后,都可以随便登录这两个站点,进入之后都会有 ...

随机推荐

  1. windows下ThinkPHP3.2.3使用memcache缓存

    准备 要使用memcache,首先要安装配置好memcache服务memcached: 下载http://downloads.northscale.com/memcached-win64-1.4.4- ...

  2. PHP webservice的使用

    提到php的webservice.之前还是比较陌生的,因为接触的少呀,几乎在所有的公司中没用过,仅仅用过的一次好像是接入一个第三方的短信通道,用的是SOAP|WSDL. 一个很极端的话“webserv ...

  3. AndroidStudio导入项目出现Your project path contains non-ASCII characters错误

    Your project path contains non-ASCII characters. This will most likely cause the build to fail on Wi ...

  4. scikit-learn算法选择图

    图片来自sklearn官网 最近事情弄完一部分了,继续开始python data science!

  5. 【leetcode】Container With Most Water

    题目描述: Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ...

  6. Linux上搭建Hadoop2.6.3集群以及WIN7通过Eclipse开发MapReduce的demo

    近期为了分析国内航空旅游业常见安全漏洞,想到了用大数据来分析,其实数据也不大,只是生产项目没有使用Hadoop,因此这里实际使用一次. 先看一下通过hadoop分析后的结果吧,最终通过hadoop分析 ...

  7. 亚马逊S3下载上传文件

    引用网址: http://www.jxtobo.com/27697.html 下载 CloudBerry Explorer http://www.cloudberrylab.com/download- ...

  8. vue-loader配合webpack的使用及安装

    vue-loader配合webpack的使用及安装: 工程文件简单的目录结构 index.html main.js   入口文件 App.vue   vue文件,官方推荐命名法 package.jso ...

  9. ecplise + hadoop 调试环境搭建

    1.需要安装包 1.1 hadoop源码包(hadoop-2.5.2-src.tar.gz) 1.2 hadoop 2X插件(hadoop2x-eclipse-plugin-master.zip) 1 ...

  10. 安装 pywin32-218.win32-py2.7.exe 报错python version 2.7 required,which was not found in the registry解决方案

    随便在一个盘下 新建register.py的文件,内容如下: #   # script to register Python 2.0 or later for use with win32all    ...