Поделиться через


Brush Class

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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

Namespace:  System.Windows.Media
Assembly:  System.Windows (in System.Windows.dll)

Syntax

'Declaration
Public MustInherit Class Brush _
    Inherits DependencyObject
public abstract 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. See Remarks for a table of predefined colors.

  • rgb
    A three-character hexadecimal value that describes a Color. 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 that describes a Color. 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 that describes a Color. The first two character 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 that describes a Color. 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 ScA value for a Color. Color does not store a specific ScA value, so the provided value will be converted and stored in 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 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 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 B.

The Brush type exposes the following members.

Constructors

  Name Description
Protected methodSupported by Silverlight for Windows Phone Brush Initializes a new instance of the Brush class.

Top

Properties

  Name Description
Public propertySupported by Silverlight for Windows Phone Dispatcher Gets the Dispatcher this object is associated with. (Inherited from DependencyObject.)
Public propertySupported by Silverlight for Windows Phone Opacity Gets or sets the degree of opacity of a Brush.
Public propertySupported by Silverlight for Windows Phone RelativeTransform Gets or sets the transformation that is applied to the brush using relative coordinates.
Public propertySupported by Silverlight for Windows Phone Transform Gets or sets the transformation that is applied to the brush.

Top

Methods

  Name Description
Public methodSupported by Silverlight for Windows Phone CheckAccess Determines whether the calling thread has access to this object. (Inherited from DependencyObject.)
Public methodSupported by Silverlight for Windows Phone ClearValue Clears the local value of a dependency property. (Inherited from DependencyObject.)
Public methodSupported by Silverlight for Windows Phone Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodSupported by Silverlight for Windows Phone 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.)
Public methodSupported by Silverlight for Windows Phone GetAnimationBaseValue Returns any base value established for a Silverlight dependency property, which would apply in cases where an animation is not active. (Inherited from DependencyObject.)
Public methodSupported by Silverlight for Windows Phone GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public methodSupported by Silverlight for Windows Phone GetType Gets the Type of the current instance. (Inherited from Object.)
Public methodSupported by Silverlight for Windows Phone GetValue Returns the current effective value of a dependency property from a DependencyObject. (Inherited from DependencyObject.)
Protected methodSupported by Silverlight for Windows Phone MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public methodSupported by Silverlight for Windows Phone ReadLocalValue Returns the local value of a dependency property, if a local value is set. (Inherited from DependencyObject.)
Public methodSupported by Silverlight for Windows Phone SetValue Sets the local value of a dependency property on a DependencyObject. (Inherited from DependencyObject.)
Public methodSupported by Silverlight for Windows Phone ToString Returns a string that represents the current object. (Inherited from Object.)

Top

Fields

  Name Description
Public fieldStatic memberSupported by Silverlight for Windows Phone OpacityProperty Identifies the Opacity dependency property.
Public fieldStatic memberSupported by Silverlight for Windows Phone RelativeTransformProperty Identifies the RelativeTransform dependency property.
Public fieldStatic memberSupported by Silverlight for Windows Phone TransformProperty Identifies the Transform dependency property.

Top

Remarks

For XAML syntaxes that take a Brush, you need to specify one of the following:

  • A Color, specified as a string to directly fill a Brush-type property in XAML attribute form. That string is implied to create a SolidColorBrush to fill the value, and the Color you specify becomes the Color property value. This is the syntax shown in the "XAML Attribute Usage" and "XAML Values" sections of this topic.

  • A nonabstract derived type of Brush as an object element, with the Brush-type property in question being specified in property element form. For details, see the XAML syntax on the reference pages for SolidColorBrush, LinearGradientBrush, RadialGradientBrush, ImageBrush, and VideoBrush. It is also possible to derive custom types from Brush.

  • A StaticResource, Binding or TemplateBinding reference to an existing Brush.

For more information and examples of the XAML syntax and illustrations of the types of brushes, see Brushes.

A Brush "paints" an area with its output. Different brushes have different types of output. Some brushes paint an area with a solid color, gradient, or image. The following list describes the different types of brushes:

Predefined Colors

You can paint using a SolidColorBrush that uses a predefined solid color. This can either be a static property name of Colors, or one of another set of color names that are processed directly as strings if specified as a XAML attribute value. See Color or SolidColorBrush for a table of named colors, and instructions on how to specify named colors in code. To use a predefined color, you can use the XAML attribute syntax for any property that takes a Brush, using the named color convention. Or you can create a SolidColorBrush and specify its Color value as a XAML attribute, using the named color convention.

Predefined Colors

Colors.

Brushes in XAML

The following table lists the different Brush types that can be used in XAML and the syntax they support. For detailed syntax information for a specific brush, see that brush's type page.

The XAML Attribute Usage in this topic is specifically the SolidColorBrush attribute syntax. The SolidColorBrush syntax is the default behavior if you specify an attribute value string for any property that expects a Brush type. However, if you use a markup extension such as Binding or StaticResource, you could reference any type of Brush.

Possible XAML Usages of Brush Classes

Class

Attribute Syntax

Object Element Syntax

SolidColorBrush

Yes

Yes

ImageBrush

No

Yes

LinearGradientBrush

No

Yes

RadialGradientBrush

No

Yes

VideoBrush

No

Yes

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Thread Safety

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

See Also

Reference

Other Resources