惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

IT之家
IT之家
Y
Y Combinator Blog
月光博客
月光博客
Blog — PlanetScale
Blog — PlanetScale
GbyAI
GbyAI
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园 - 三生石上(FineUI控件)
S
SegmentFault 最新的问题
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
美团技术团队
雷峰网
雷峰网
酷 壳 – CoolShell
酷 壳 – CoolShell
Last Week in AI
Last Week in AI
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
有赞技术团队
有赞技术团队
博客园 - 司徒正美
V
Visual Studio Blog
小众软件
小众软件
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
T
Tailwind CSS Blog
Apple Machine Learning Research
Apple Machine Learning Research
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
A
About on SuperTechFans
The Cloudflare Blog

博客园 - caoyang.org

jupyter centos 6 yum源记录,离线下载rpm包的办法 使用命令提示符连接到无线网络 linux系统的ssh服务开启方法 nodejs dateformat date-utils nodejs async nodejs dateformat date-utils nodejs timer block-timer timer-ease linux 修改 ssh 的端口号,启动hg服务 linux 下添加 路由 【msdn wpf forum翻译】TextBox中文本 中对齐 的方法 - caoyang.org 【msdn wpf forum翻译】TextBlock等类型的默认样式(implicit style)为何有时不起作用? 【msdn wpf forum翻译】获取当前窗口焦点所在的元素 【msdn wpf forum翻译】如何在wpf程序(程序激活时)中捕获所有的键盘输入,而不管哪个元素获得焦点? 【msdn wpf forum翻译】在wpf程序中显示一个doc文件的内容 《Applications=Code+Markup》读书笔记 1(第一章 初识Application和Window) Bind Enum to Combobox.SelectedIndex 如何捕获正在执行的函数名? wpf中显示HTML(转自http://steeven.cnblogs.com/archive/2006/06/12/424258.html)
《Applications=Code+Markup》读书笔记 2(第二章 基本画刷)
caoyang.org · 2007-09-24 · via 博客园 - caoyang.org

Color

可以new出来,也可以通过它的静态方法Color.FromRgb(r,g,b)或Color.FromArgb(a,r,g,b)获得

Color是一个struct.

System.Window.Media命名空间下还有一些Colors的类,包含141个static的只读的属性 (whose names begin alphabetically with AliceBlue and AntiqueWhite and conclude with Yellow and YellowGreen).

Brush的继承关系

其中本章介绍SolidColorBrush和GradientBrush (abstract) (以及其子类LinearGradientBrush RadialGradientBrush). 以下为类继承关系图:

Object
    DispatcherObject (abstract)
          DependencyObject
                Freezable (abstract)
                       Animatable (abstract)
                             Brush (abstract)
                                   GradientBrush (abstract)
                                         LinearGradientBrush
                                         RadialGradientBrush
                                   SolidColorBrush
                                   TileBrush (abstract)
                                          DrawingBrush
                                          ImageBrush
                                          VisualBrush

Brush广泛地应用于Control的Background等涉及到颜色的属性

在WPF中,颜色Color是一个单纯的结构,而Brush才是色彩的主演。

如何构造一个SolidColorBrush呢?

  1. SolidColorBrush的构造函数接收一个参数Color,而Color可通过本章最初介绍的方法获得。
  2. SolidColorBrush有一个属性 Color,可通过赋值改变SolidColorBrush的颜色。
  3. Brushes有和Colors对应的141种预定义的单色,但不能直接赋值:
    //get an Invalid Operation Exception that states 
    //"Cannot set a property on object '#FF000000' because it is in a read-only state." 
    SolidColorBrush brush = Brushes.Black;
    //可以这样:
    SolidColorBrush brush = Brushes.Black.Clone();

注:以上第三点,究其原因,是因为Brushes的静态变量Black已经frozen了。

The SolidColorBrush objects returned from the Brushes class are in a frozen state,
which means they can no longer be altered.
Like the Changed event, freezing is implemented in the Freezable class, from which Brush inherits.
If the CanFreeze property of a Freezable object is true,
it's possible to call the Freeze method to render the object frozen and unchangeable.
The IsFrozen property indicates this state by becoming true.
Freezing objects can improve performance because they no longer need to be monitored for changes.
A frozen Freezable object can also be shared across threads, while an unfrozen Freezable object cannot.
Although you cannot unfreeze a frozen object, you can make an unfrozen copy of it.

系统画刷以及其优点

SystemColors与Brushes和Colors相似,例如,它可以这样获取颜色及画刷:

SystemColors.WindowColorBrush和SystemColors.WindowColor 也可以这样修改画刷:

Brush brush = new SystemColorBrush(SystemColors.WindowColor);

GradientBrush

包括LinearGradientBrush和RadialGradientBrush

LinearGradientBrush 线性梯度渐变画刷

介绍了2种构造函数

  1. new LinearGradientBrush(Colors.Red, Colors.Blue, new Point(0, 0), new Point(1, 1));
  2. new LinearGradientBrush(clr1, clr2, angle);

SpreadMethod 、GradientStops、StartPoint、EndPoint等属性

  1. 通过设置这些属性,可以改变GradientBrush的样子。

RadialGradientBrush 径向梯度渐变画刷

与LinearGradientBrush相仿,只是色彩渐变的方向是径向

作者给出了几个很有趣的例子,形象地说明了这些Brush的特点。

本章最后介绍了Control类的属性BorderBrush、BorderThickness、Foreground

并引出了下一章:The Concept of Content