WPF整理-使用用户选择主题的颜色和字体
2013-06-29 23:12
537 查看
“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如下:
注意这个,和前面的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如下:
两者采用不同的方法实现相同的效果。
对比如下:
效果如下:
如果我们改变系统地主题:
再次编译运行,则程序运行如下:
看不出区别~
但,若我们程序保持运行,改变主题,则程序界面随之改变如下:
这就是两者的区别。
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>
效果如下:
如果我们改变系统地主题:
再次编译运行,则程序运行如下:
看不出区别~
但,若我们程序保持运行,改变主题,则程序界面随之改变如下:
这就是两者的区别。
相关文章推荐
- Xcode 4使用技巧:使用字体和颜色主题
- 如何使用hugo搭建个人博客(二):修改主题:颜色,字体,布局
- 潘鹏整理WPF(1)颜色、字体、光标
- jquery-ui 的 主题 选择什么颜色? 建议使用html5 的标准进行书写, 更简洁!
- Web 前端颜色值--字体--使用,整理整理
- 关于VS的主题、字体、文本颜色的更改与选择
- GTK+ 消息对话框 属性对话框 字体选择对话框 颜色选择对话框 的使用例子
- Web 前端颜色值--字体--使用,整理整理
- 使用Qt 4如何设置QLabe中字体的颜色
- 【myEcplise2015 更换主题+字体颜色】
- 使用poi对excel条件格式设置字体颜色使用自定义的颜色
- .Net学习笔记----2015-07-02(选择文件对话框、保存对话框、字体和颜色对话框)
- (整理)HTML字体标记:标题字体,字体大小,物理字体,逻辑字体,字体颜色,客户端字体,字符实体
- iOS使用NSMutableAttributedString 实现富文本(不同颜色字体、划线等等)
- vc修改列表框LISTBOX的背景颜色及字体颜色及其使用方法
- LISTBOX控件:vc修改列表框LISTBOX的背景颜色及字体颜色及其使用方法
- iOS使用NSMutableAttributedString 实现富文本(不同颜色字体、下划线等)
- 【整理】如何使用C#实现网易博客中圈子用户数据的采集
- 使用NSMutableAttributedString 实现富文本(不同颜色字体、下划线等)
- IOS - 使用NSMutableAttributedString 实现富文本(不同颜色字体、下划线等)