Brush class

Applies to Windows and Windows Phone

Defines objects used to paint graphical objects. Classes that derive from Brush describe how the area is painted.

Inheritance

Object
  DependencyObject
    Brush

Syntax


public class Brush : DependencyObject


<object property="predefinedColorName"/>
- 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

predefinedColorName

The name of a color. This can either be a static property name of Colors, or one of the color names that are processed directly as strings.

rgb

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

argb

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

rrggbb

A six-character hexadecimal value that describes a Color. The first two character specify the color's Color.R value, the next two specify its Color.G value, and the final two specify its Color.B value. For example, 0000FF.

aarrggbb

An eight-character hexadecimal value that describes a Color. The first two characters specify the color's Color.A value, the next two specify its Color.R value, the next two specify its Color.G value, and the final two specify its Color.B value. For example, FF0000FF.

scA

The ScA value for a Color. Color does not store a specific ScA value, so the provided value will be converted and stored in Color.A.

scR

The ScR value for a Color. Color does not store a specific ScR value, so the provided value will be converted and stored in Color.R.

scG

The ScG value for a Color. Color does not store a specific ScG value, so the provided value will be converted and stored in Color.G.

scB

The ScB value for a Color. Color does not store a specific ScB value, so the provided value will be converted and stored in Color.B.

Attributes

[MarshalingBehavior(Agile)]
[Threading(Both)]
[Version(0x06020000)]
[WebHostHidden()]

Members

The Brush class has these types of members:

Constructors

The Brush class has these constructors.

ConstructorDescription
Brush Provides base class initialization behavior for Brush-derived classes.

 

Methods

The Brush 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 Brush class has these properties.

PropertyAccess typeDescription

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.

OpacityProperty

Read-onlyIdentifies the Opacity dependency property.

RelativeTransform

Read/writeGets or sets the transformation that is applied to the brush using relative coordinates.

RelativeTransformProperty

Read-onlyIdentifies the RelativeTransform dependency property.

Transform

Read/writeGets or sets the transformation that is applied to the brush.

TransformProperty

Read-onlyIdentifies the Transform dependency property.

 

Remarks

For examples and further explanation of the UI drawing concepts represented by Brush, see Quickstart: Using brushes.

Brushes as XAML resources

Each of the Brush types that can be declared in XAML (SolidColorBrush, LinearGradientBrush, ImageBrush) is intended to be defined as a resource, so that you can reuse that brush as a resource throughout your app. The XAML syntax shown for Brush types is appropriate for defining the brush as a resource. When you declare a brush as a resource, you also need an x:Key attribute that you'll later use to refer to that resource from other UI definitions. For more info on XAML resources and how to use x:Key, see ResourceDictionary and XAML resource references.

The advantage of declaring brushes as resources is that it reduces the number of runtime objects that are needed to construct a UI: the brush is now shared as a common resource that's providing values for multiple parts of the object graph.

If you look at the existing control template definitions for Windows Runtime XAML controls, you'll see that the templates use brush resources extensively. Many of these resources are system resources, and they use the ThemeResource markup extension for the resource reference rather than StaticResource. For more info on how to use system resource brushes in your own control template XAML, see XAML theme resources reference.

Brush derived classes

Brush is the parent class for several derived classes that either implement practical brushes that paint UI regions, or are intermediate base classes for such brushes:

Requirements

Minimum supported client

Windows 8 [Windows Store apps only]

Minimum supported server

Windows Server 2012 [Windows Store apps only]

Minimum supported phone

Windows Phone 8.1 [Windows Runtime apps only]

Namespace

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

Metadata

Windows.winmd

See also

DependencyObject
SolidColorBrush
Color
Colors
Quickstart: Using brushes
Quickstart: Image and ImageBrush
ResourceDictionary and XAML resource references

 

 

Show:
© 2014 Microsoft