Defines objects used to paint graphical objects. Classes that derive from Brush describe how the area is painted.
Namespace:
System.Windows.Media
Assembly:
PresentationCore (in PresentationCore.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
Visual Basic (Declaration)
<TypeConverterAttribute(GetType(BrushConverter))> _
<LocalizabilityAttribute(LocalizationCategory.None, Readability := Readability.Unreadable)> _
Public MustInherit Class Brush _
Inherits Animatable _
Implements IFormattable
[TypeConverterAttribute(typeof(BrushConverter))]
[LocalizabilityAttribute(LocalizationCategory.None, Readability = Readability.Unreadable)]
public abstract class Brush : Animatable,
IFormattable
[TypeConverterAttribute(typeof(BrushConverter))]
[LocalizabilityAttribute(LocalizationCategory::None, Readability = Readability::Unreadable)]
public ref class Brush abstract : public Animatable,
IFormattable
public abstract class Brush extends Animatable implements IFormattable
For XAML information, see the Remarks section.
A Brush "paints" or "fills" an area with its output. Different brushes have different types of output. Some brushes paint an area with a solid color, others with a gradient, pattern, image, or drawing. The following list describes the different types of WPF brushes:
Predefined Brushes
Use the Brushes class to paint an object using a predefined solid color, such as AliceBlue or Red.
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.
For an example showing how to quickly paint an area with a solid color, see How to: Paint an Area with a Solid Color.
Freezable Features
Notes to Inheritors: When you inherit from the Brush class, you must override the CreateInstanceCore method. Depending on whether your class must perform additional initialization work or contains non-dependency property data members, you might need to override additional Freezable methods. For more information about inheriting from Freezable types, 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.
xaml
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 Solid Colors and Gradients Overview 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
System..::.Object
System.Windows.Threading..::.DispatcherObject
System.Windows..::.DependencyObject
System.Windows..::.Freezable
System.Windows.Media.Animation..::.Animatable
System.Windows.Media..::.Brush
System.Windows.Media..::.GradientBrush
System.Windows.Media..::.SolidColorBrush
System.Windows.Media..::.TileBrush
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 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
.NET Framework
Supported in: 3.5, 3.0
Reference
Other Resources