






















可以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).
其中本章介绍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
在WPF中,颜色Color是一个单纯的结构,而Brush才是色彩的主演。
//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);
包括LinearGradientBrush和RadialGradientBrush
与LinearGradientBrush相仿,只是色彩渐变的方向是径向
作者给出了几个很有趣的例子,形象地说明了这些Brush的特点。
并引出了下一章:The Concept of Content
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。