Defines objects used to paint graphical objects. Classes that derive from describe how the area is painted.
Assembly: PresentationCore (in PresentationCore.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
A "paints" or "fills" an area with its output. Different brushes have different types of output. Some brushes paint an area with a solid color, others with a gradient, pattern, image, or drawing. The following list describes the different types of WPF brushes:
LinearGradientBrush: Paints an area with a linear gradient.
RadialGradientBrush: Paints an area with a radial gradient.
VisualBrush: Paints an area with a Visual object. A VisualBrush enables you to duplicate content from one portion of your application into another area; it's very useful for creating reflection effects and magnifying portions of the screen.
Brushes in XAML
The following table lists the different types that can be used in XAML and the syntax they support. For detailed syntax information for a specific brush, see that brush's type page.
Object Element Syntax
For an example showing how to quickly paint an area with a solid color, see How to: Paint an Area with a Solid Color.
When you inherit from the class, you must override the CreateInstanceCore method. Depending on whether your class must perform additional initialization work or contains non-dependency property data members, you might need to override additional Freezable methods. For more information about inheriting from Freezable types, see the Freezable Objects Overview.
To paint an area with a solid color, you can use a predefined system brush, such as Red or Blue, or you can create a new SolidColorBrush and describe its Color using alpha, red, green, and blue values. In XAML, you may also paint an area with a solid color by using hexidecimal notation.
The following examples uses each of these techniques to paint a Rectangle blue.
Using a Predefined Brush
In the following example uses the predefined brush Blue to paint a rectangle blue.
For a list of predefined brushes, see the Brushes class.xaml
Using Hexadecimal Notation
The next example uses 8-digit hexadecimal notation to paint a rectangle blue.
Using ARGB Values
<Rectangle Width="50" Height="50"> <Rectangle.Fill> <SolidColorBrush> <SolidColorBrush.Color> <!-- Describes the brush's color using RGB values. Each value has a range of 0-255. R is for red, G is for green, and B is for blue. A is for alpha which controls transparency of the color. Therefore, to make a completely transparent color (invisible), use a value of 0 for Alpha. --> <Color A="255" R="0" G="0" B="255" /> </SolidColorBrush.Color> </SolidColorBrush> </Rectangle.Fill> </Rectangle>
Rectangle myRgbRectangle = new Rectangle(); myRgbRectangle.Width = 50; myRgbRectangle.Height = 50; SolidColorBrush mySolidColorBrush = new SolidColorBrush(); // Describes the brush's color using RGB values. // Each value has a range of 0-255. mySolidColorBrush.Color = Color.FromArgb(255, 0, 0, 255); myRgbRectangle.Fill = mySolidColorBrush;
For other ways of describing color, see the Color structure.
|How to: Make a UIElement Transparent or Semi-Transparent||This example shows how to make a UIElement transparent or semi-transparent. To make an element transparent or semi-transparent, you set its Opacity property. A value of 0.0 makes the element completely transparent, while a value of 1.0 makes the element completely opaque. A value of 0.5 makes the element 50% opaque, and so on. An element's Opacity is set to 1.0 by default.|
|How to: Paint an Area with a Linear Gradient||This example shows how to use the LinearGradientBrush class to paint an area with a linear gradient. In the following example, the Fill of a Rectangle is painted with a diagonal linear gradient that transitions from yellow to red to blue to lime green.|
|How to: Paint an Area with a Radial Gradient||This example shows how to use the RadialGradientBrush class to paint an area with a radial gradient.|
|How to: Paint an Area with an Image||This example shows how to use the ImageBrush class to paint an area with an image. An ImageBrush displays a single image, which is specified by its ImageSource property.|
|How to: Paint an Area with a System Brush||The SystemColors class provides access to system brushes and colors, such as ControlBrush, ControlBrushKey, and DesktopBrush. A system brush is a SolidColorBrush object that paints an area with the specified system color. A system brush always produces a solid fill; it can't be used to create a gradient.|
|How to: Paint an Area with a Visual||This example shows how to use the VisualBrush class to paint an area with a Visual.|
Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.