SolidColorBrush class

0 out of 10 rated this helpful - Rate this topic

Paints an area with a solid color.

Inheritance

Object
  DependencyObject
    Brush
      SolidColorBrush

Syntax

Public NotInheritable Class SolidColorBrush  
    Inherits Brush

<SolidColorBrush .../>
-or-
<SolidColorBrush>colorString</SolidColorBrush>


<SolidColorBrush Color="predefinedColorName"/>
- or -
<SolidColorBrush Color="#rgb"/>
- or -
<SolidColorBrush Color="#argb"/>
- or -
<SolidColorBrush Color="#rrggbb"/>
- or -
<SolidColorBrush Color="#aarrggbb"/>
- or -
<SolidColorBrush Color="sc#scR,scG,scB"/>
- or -
<SolidColorBrush Color="sc#scA,scR,scG,scB"/>

XAML Values

predefinedColor

One of the colors predefined by the Colors class (static properties), or one of the other named colors.

rgb

A three-character hexadecimal value. The first character specifies the color's R value, the second character specifies the G value, and the third character specifies the B value. For example, 00F.

argb

A four-character hexadecimal value. The first character specifies the color's A value, the second character specifies its R value, the third character specifies the G value, and the fourth character specifies its B value. For example, F00F.

rrggbb

A six-character hexadecimal value. The first two characters 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-character hexadecimal value. The first two characters 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

The color's ScA value as a value between 0 and 1. ScA is not exposed as a Color property directly.

scR

The color's ScR value as a value between 0 and 1. ScR is not exposed as a Color property directly.

scG

The color's ScG value as a value between 0 and 1. ScG is not exposed as a Color property directly.

scB

The color's ScB value as a value between 0 and 1. ScB is not exposed as a Color property directly.

Attributes

ActivatableAttribute(Windows.UI.Xaml.Media.ISolidColorBrushFactory, NTDDI_WIN8)
ActivatableAttribute(NTDDI_WIN8)
ContentPropertyAttribute(Name=Color)
MarshalingBehaviorAttribute(Agile)
StaticAttribute(Windows.UI.Xaml.Media.ISolidColorBrushStatics, NTDDI_WIN8)
ThreadingAttribute(Both)
VersionAttribute(NTDDI_WIN8)
WebHostHiddenAttribute()

Members

The SolidColorBrush class has these types of members:

Constructors

The SolidColorBrush class has these constructors.

ConstructorDescription
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.

 

Methods

The SolidColorBrush class has these methods. It also inherits methods from the Object class.

MethodDescription
ClearValue Clears the local value of a dependency property. (Inherited from DependencyObject)
GetAnimationBaseValue Returns any base value established for a dependency property, which would apply in cases where an animation is not active. (Inherited from DependencyObject)
GetValue Returns the current effective value of a dependency property from a DependencyObject. (Inherited from DependencyObject)
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)

 

Properties

The SolidColorBrush class has these properties.

PropertyAccess typeDescription

Color

Read/writeGets or sets the color of this SolidColorBrush.

ColorProperty

Read-onlyIdentifies the Color dependency property.

Dispatcher

Read-onlyGets the CoreDispatcher that this object is associated with. (Inherited from DependencyObject)

Opacity

Read/writeGets or sets the degree of opacity of a Brush. (Inherited from Brush)

RelativeTransform

Read/writeGets or sets the transformation that is applied to the brush using relative coordinates. (Inherited from Brush)

Transform

Read/writeGets or sets the transformation that is applied to the brush. (Inherited from Brush)

 

Examples

One of the most common operations in any presentation technology is to paint an area with a solid color. To accomplish this task, use the SolidColorBrush class. There are several different ways to paint with a SolidColorBrush:

  • 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.


<Canvas
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

  <!-- This rectangle's fill is painted with a red SolidColorBrush,
       described using a named color. -->
  <Rectangle Width="100" Height="100" Fill="Red" />
</Canvas>


  • 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 this next example, the Fill of a Rectangle is set to fully opaque red using hexadecimal notation.


<Canvas 
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

  <!-- This rectangle's background is painted with a red SolidColorBrush,
       described using hexadecimal notation. -->
  <Rectangle Width="100" Height="100" Fill="#FFFF0000" />
</Canvas>


  • 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 Fill properties 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.


<Canvas 
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
 
  <!-- Both of these rectangles' fills are painted with red
       SolidColorBrush objects, described using object element
       syntax. -->
  <Rectangle Width="100" Height="100">
    <Rectangle.Fill>
      <SolidColorBrush Color="Red" />
    </Rectangle.Fill>
  </Rectangle>

  <Rectangle Width="100" Height="100" Canvas.Top="110">
    <Rectangle.Fill>
      <SolidColorBrush Color="#FFFF0000" />
    </Rectangle.Fill>
  </Rectangle> 
</Canvas>


Requirements

Minimum supported client

Windows 8 [Windows Store apps only]

Minimum supported server

Windows Server 2012 [Windows Store apps only]

Namespace

Windows.UI.Xaml.Media
Windows::UI::Xaml::Media [C++]

Metadata

Windows.winmd

See also

Brush

 

 

Build date: 12/4/2012

Did you find this helpful?
(1500 characters remaining)
© 2013 Microsoft. All rights reserved.