Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

SolidColorBrush Class

Paints an area with a solid color.

Namespace: System.Windows.Media
Assembly: PresentationCore (in presentationcore.dll)
XML Namespace:  http://schemas.microsoft.com/winfx/2006/xaml/presentation

public sealed class SolidColorBrush : Brush
public final class SolidColorBrush extends Brush
public final class SolidColorBrush extends Brush
<SolidColorBrush .../>
<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"/>
 predefinedBrushName  The name of a brush defined by the Brushes class, such as Blue or Orange.   rgb  A three-digit hexadecimal number that describes this brush's Color. The first digit specifies the color's R value, the second digit specifies the G value, and the third digit specifies the B value. For example, 00F.  argb  A four-digit hexadecimal number that describes this brush's Color. The first digit specifies the color's A value, the second digit specifies its R value, the next digit specifies the G value, and the final digit specifies its B value. For example, F00F.  rrggbb  A six-digit hexadecimal number that describes this brush's Color. The first two digits specify the color's R value, the next two specify its G value, and the final two specify its B value. For example, 0000FF.  aarrggbb  An eight-digit hexadecimal number that describes this brush's Color. The first two digits specify the color's A value, the next two specify its R value, the next two specify its G value, and the final two specify its B value. For example, FF0000FF.  scA   Single  The ScA value of this brush's Color.  scR   Single  The ScR value of this brush's Color.  scG   Single  The ScG value of this brush's Color.  scB   Single  The ScB value of this brush's Color.  profileUri   System.Uri  The International Color Consortium (ICC) or Image Color Management (ICM) color profile.  alphaValue   System.Single  The alpha channel color value. The value range is from 0.0 through 1.0.  colorValue  A comma-delimited list of three to eight values that represent the color channels of the color profile. The value range is from 0.0 through 1.0. 

For convenience, the Brushes class provides a set of commonly used SolidColorBrush objects, such as Blue and Yellow.

Freezable Features: Because it inherits from the Freezable class, the SolidColorBrush class provides several special features: SolidColorBrush 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 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.

<Rectangle Width="50" Height="50" Fill="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.

Related Topics

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.

More Code

How to: Animate the Color or Opacity of a SolidColorBrush

This example shows how to animate the Color and Opacity of a SolidColorBrush.

System.Object
   System.Windows.Threading.DispatcherObject
     System.Windows.DependencyObject
       System.Windows.Freezable
         System.Windows.Media.Animation.Animatable
           System.Windows.Media.Brush
            System.Windows.Media.SolidColorBrush

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

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 Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions

Show:
© 2014 Microsoft