Assembly: PresentationCore (in presentationcore.dll)
XML Namespace: http://schemas.microsoft.com/winfx/2006/xaml/presentation
Color names in Windows Presentation Foundation (WPF) match the color names in Microsoft .NET Framework, Windows Forms, and Microsoft Internet Explorer. These colors and their names are based on the UNIX X11 color values.
The following image shows the color of each predefined brush, its name, and its hexadecimal value.
Color table including a color swatch, the color name, and the hexadecimal value
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.
// Create a rectangle and paint it with // a predefined brush. Rectangle myPredefinedBrushRectangle = new Rectangle(); myPredefinedBrushRectangle.Width = 50; myPredefinedBrushRectangle.Height = 50; myPredefinedBrushRectangle.Fill = Brushes.Blue;
For a list of predefined brushes, see the Brushes class.
Using Hexadecimal Notation
The next example uses 8-digit hexadecimal notation to paint a rectangle blue.
<!-- Note that the first two characters "FF" of the 8-digit value is the alpha which controls the transparency of the color. Therefore, to make a completely transparent color (invisible), use "00" for those digits (e.g. #000000FF). --> <Rectangle Width="50" Height="50" Fill="#FF0000FF" />
Using ARGB Values
The next example creates a SolidColorBrush 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 SolidColorBrush and additional examples, see the Painting with WPF Brushes overview.
This code example is part of a larger example provided for the SolidColorBrush class. For the complete sample, see the Brushes Sample.
Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter EditionThe Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.