Paints an area with a solid color.
Assembly: PresentationCore (in PresentationCore.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
<object property="predefinedBrushName"/> - or - <object property="#rgb"/> - or - <object property="#argb"/> - or - <object property="#rrggbb"/> - or - <object property="#aarrggbb"/> - or - <object property="sc#scA,scR,scG,scB"/> - or - <object property="ContextColor profileUri alphaValue,colorValue"/>
Freezable Features: Because it inherits from the Freezable class, the class provides several special features: objects can be declared as resources, shared among multiple objects, made read-only to improve performance, cloned, and made thread-safe. For more information about the different features provided by Freezable objects, 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 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
The next example creates a and describes its Color using the ARGB values for the color blue.
<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.
For more information about and additional examples, see the Painting with Solid Colors and Gradients Overview overview.
This code example is part of a larger example provided for the class. For the complete sample, see the Brushes Sample.
|How to: Animate the Color or Opacity of a SolidColorBrush||This example shows how to animate the Color and Opacity of a .|
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.