Color
You can use the new method or its static method color. fromrgb (R, G, B) or color. fromargb (A, R, G, B) to obtain
Color is a struct.
There are also some colors classes in the system. Window. Media namespace, including 141 static read-only attributes (whose names begin alphabetically with aliceblue and antiquewhite and conclude with yellow and yellowgreen ).
Inheritance relationship of the brush
This chapter describes solidcolorbrush and gradientbrush (abstract) (and its subclass lineargradientbrush radialgradientbrush). The following is the class inheritance relationship diagram:
Object dispatcherobject (abstract) dependencyobject freezable (abstract) animatable (abstract) brush (abstract) gradientbrush (abstract) lineargradientbrush radialgradientbrush solidcolorbrush tilebrush (abstract) drawingbrush imagebrush visualbrush
Brush is widely used in control background and other color-related attributes.
In WPF, color is a simple structure, while brush is the main character of color.
How to construct a solidcolorbrush?
- The constructor of solidcolorbrush receives a color parameter, which can be obtained through the method first introduced in this chapter.
- Solidcolorbrush has a property color that can be used to change the color of a solidcolorbrush by assigning values.
- Brushes has 141 predefined monochrome colors corresponding to colors, but cannot be assigned directly:
// 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; // you can do this: solidcolorbrush brush = brushes. black. clone ();
Note: The third reason is that the static variable black of brushes has been 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 with SS threads, while an unfrozen freezable object cannot. although you cannot unfreeze a frozen object, you can make an unfrozen copy of it.
System Image painter and its advantages
Systemcolors is similar to brushes and colors. For example, it can obtain the color and paint brush as follows:
Systemcolors. windowcolorbrush and systemcolors. windowcolor can also be modified as follows:
Brush = new systemcolorbrush (systemcolors. windowcolor );
Gradientbrush
Including lineargradientbrush and radialgradientbrush
Lineargradientbrush linear gradient Paint Brush Two constructor types are introduced.
- New lineargradientbrush (colors. Red, colors. Blue, new point (0, 0), new point (1, 1 ));
- New lineargradientbrush (clr1, clr2, angle );
Attributes such as spreadmethod, gradientstops, startpoint, and Endpoint
- By setting these attributes, you can change the appearance of gradientbrush.
Radialgradientbrush radial gradient Paint Brush
Similar to lineargradientbrush, only the direction of the color gradient is radial
The author provides several interesting examples to illustrate the features of these brushes.
This chapter introduces the attributes of the control class borderbrush, borderthickness, and foreground.
introduces the next chapter: The concept of content