SolidColorBrush Class
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Paints an area with a solid color.
System.Windows::DependencyObject
System.Windows.Media::Brush
System.Windows.Media::SolidColorBrush
Assembly: System.Windows (in System.Windows.dll)
XMLNS for XAML: Not mapped to an xmlns.
<SolidColorBrush .../> -or- <SolidColorBrush>colorString</SolidColorBrush>
<object property="predefinedColor"/> - or - <object property="#rgb"/> - or - <object property="#argb"/> - or - <object property="#rrggbb"/> - or - <object property="#aarrggbb"/> - or - <object property="sc#scR,scG,scB"/> - or - <object property="sc# scA,scR,scG,scB"/>
XAML Values
The SolidColorBrush type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | SolidColorBrush() | Initializes a new instance of the SolidColorBrush class with no color. |
![]() | SolidColorBrush(Color) | Initializes a new instance of the SolidColorBrush class with the specified Color. |
| Name | Description | |
|---|---|---|
![]() | Color | Gets or sets the color of this SolidColorBrush. |
![]() | Dispatcher | Gets the Dispatcher this object is associated with. (Inherited from DependencyObject.) |
![]() | Opacity | Gets or sets the degree of opacity of a Brush. (Inherited from Brush.) |
![]() | RelativeTransform | Gets or sets the transformation that is applied to the brush using relative coordinates. (Inherited from Brush.) |
![]() | Transform | Gets or sets the transformation that is applied to the brush. (Inherited from Brush.) |
| Name | Description | |
|---|---|---|
![]() | CheckAccess | Determines whether the calling thread has access to this object. (Inherited from DependencyObject.) |
![]() | ClearValue | Clears the local value of a dependency property. (Inherited from DependencyObject.) |
![]() | Equals(Object) | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) |
![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.) |
![]() | GetAnimationBaseValue | Returns any base value established for a Windows Phone dependency property, which would apply in cases where an animation is not active. (Inherited from DependencyObject.) |
![]() | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | GetValue | Returns the current effective value of a dependency property from a DependencyObject. (Inherited from DependencyObject.) |
![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() | ReadLocalValue | Returns the local value of a dependency property, if a local value is set. (Inherited from DependencyObject.) |
![]() | SetValue | Sets the local value of a dependency property on a DependencyObject. (Inherited from DependencyObject.) |
![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
The SolidColorBrush is the most basic brush that applies an appearance to an object. A SolidColorBrush can be specified in XAML as an attribute value, through a type conversion syntax that uses several conventions for the meaning of the string for specifying a color. Other brushes (for example LinearGradientBrush) require a property element syntax (unless you use a reference, such as {StaticResource}). Object element syntax for a SolidColorBrush is possible, and is useful for the following reasons:
You want to provide a Name to the object element and target its properties later.
You are defining a SolidColorBrush as a resource.
You are setting an Opacity on the SolidColorBrush.
You can animate a SolidColorBrush using either ColorAnimation or ColorAnimationUsingKeyFrames. Usually this is done not by animating the Color property of a SolidColorBrush, but is instead by using indirect targeting of a property such as Shape::Fill that takes a Brush. The ColorAnimation reference topic shows an example.
A SolidColorBrush is created as part of a type conversion syntax enabled by the Brush class and by SolidColorBrush itself. The syntax is described above in the "XAML Attribute Usage" subsection of the Syntax section. This syntax enables you to specify a string value for an attribute that takes a Brush, and the string is interpreted within a number of possible conventions, which include named colors, RGB, or ScRGB. Both RGB and ScRBG can specify an alpha value. For more information on the XAML syntax, see Color and Brush.

Setting Predefined Colors for a SolidColorBrush in Code
Setting predefined colors for the 16 color names that are defined as Colors static values uses the static values as the setting value, which can be done either with the constructor overload or by setting Color as a property after construction.
//constructor technique SolidColorBrush scb = new SolidColorBrush(Colors.Black); //postconstruction technique SolidColorBrush scb2 = new SolidColorBrush(); scb2.Color = Colors.Black;
One of the most common operations in any presentation technology is to paint an area with a solid color. To accomplish this task, Windows Phone provides the SolidColorBrush class. The following sections describe the different ways to paint with a SolidColorBrush.
To paint an area with a solid color in XAML, use one of the following options:
Select a predefined SolidColorBrush by name. For example, you can set the Fill of a Rectangle to Red or MediumBlue. The example uses the name of a predefined SolidColorBrush to set the Fill of a Rectangle.
<!-- This rectangle's fill is painted with a red SolidColorBrush, described using a named color. --> <Rectangle Width="100" Height="100" Margin="20" Fill="Red" />
Choose a color from the 32-bit color palette by specifying the amounts of red, green, and blue to combine into a single solid color. The format for specifying a color from the 32-bit palette is #rrggbb, where rr is a two character hexadecimal number specifying the relative amount of red, gg specifies the amount of green, and bb specifies the amount of blue. Additionally, the color can be specified as #aarrggbb, where aa specifies the alpha value, or transparency, of the color. This approach enables you to create colors that are partially transparent. In the following example, the Fill of a Rectangle is set to fully opaque red using hexadecimal notation.
<!-- This rectangle's background is painted with a red SolidColorBrush, described using hexadecimal notation. --> <Rectangle Width="100" Height="100" Margin="20" Fill="#FFFF0000" />
Use property element syntax to describe a SolidColorBrush. This syntax is more verbose but enables you to specify additional settings, such as the brush's opacity. In the following example, the Fillproperties of two Rectangle elements are set to fully opaque red. The first brush's color is described using a predefined color name. The second brush's color is described using hexadecimal notation.
<!-- Both of these rectangles' fills are painted with red SolidColorBrush objects, described using object element syntax. --> <Rectangle Width="100" Height="100" Margin="20"> <Rectangle.Fill> <SolidColorBrush Color="Red" /> </Rectangle.Fill> </Rectangle> <Rectangle Width="100" Height="100" Margin="20"> <Rectangle.Fill> <SolidColorBrush Color="#FFFF0000" /> </Rectangle.Fill> </Rectangle>




