DrawingBrush Class
Paints an area with a Drawing, which can include shapes, text, video, images, or other drawings.
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
The DrawingBrush type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | DrawingBrush() | Initializes a new instance of the DrawingBrush class. The resulting brush has no content. |
![]() | DrawingBrush(Drawing) | Initializes a new instance of the DrawingBrush class that contains the specified Drawing. |
| Name | Description | |
|---|---|---|
![]() | AlignmentX | Gets or sets the horizontal alignment of content in the TileBrush base tile. (Inherited from TileBrush.) |
![]() | AlignmentY | Gets or sets the vertical alignment of content in the TileBrush base tile. (Inherited from TileBrush.) |
![]() | CanFreeze | Gets a value that indicates whether the object can be made unmodifiable. (Inherited from Freezable.) |
![]() | DependencyObjectType | Gets the DependencyObjectType that wraps the CLR type of this instance. (Inherited from DependencyObject.) |
![]() | Dispatcher | Gets the Dispatcher this DispatcherObject is associated with. (Inherited from DispatcherObject.) |
![]() | Drawing | Gets or sets the Drawing that describes the contents of this DrawingBrush. |
![]() | HasAnimatedProperties | Gets a value that indicates whether one or more AnimationClock objects is associated with any of this object's dependency properties. (Inherited from Animatable.) |
![]() | IsFrozen | Gets a value that indicates whether the object is currently modifiable. (Inherited from Freezable.) |
![]() | IsSealed | Gets a value that indicates whether this instance is currently sealed (read-only). (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.) |
![]() | Stretch | Gets or sets a value that specifies how the content of this TileBrush stretches to fit its tiles. (Inherited from TileBrush.) |
![]() | TileMode | Gets or sets a value that specifies how a TileBrush fills the area that you are painting if the base tile is smaller than the output area. (Inherited from TileBrush.) |
![]() | Transform | Gets or sets the transformation that is applied to the brush. This transformation is applied after the brush's output has been mapped and positioned. (Inherited from Brush.) |
![]() | Viewbox | Gets or sets the position and dimensions of the content in a TileBrush tile. (Inherited from TileBrush.) |
![]() | ViewboxUnits | Gets or sets a value that specifies whether the Viewbox value is relative to the bounding box of the TileBrush contents or whether the value is absolute. (Inherited from TileBrush.) |
![]() | Viewport | Gets or sets the position and dimensions of the base tile for a TileBrush. (Inherited from TileBrush.) |
![]() | ViewportUnits | Gets or sets a BrushMappingMode enumeration that specifies whether the value of the Viewport, which indicates the size and position of the TileBrush base tile, is relative to the size of the output area. (Inherited from TileBrush.) |
| Name | Description | |
|---|---|---|
![]() | ApplyAnimationClock(DependencyProperty, AnimationClock) | Applies an AnimationClock to the specified DependencyProperty. If the property is already animated, the SnapshotAndReplace handoff behavior is used. (Inherited from Animatable.) |
![]() | ApplyAnimationClock(DependencyProperty, AnimationClock, HandoffBehavior) | Applies an AnimationClock to the specified DependencyProperty. If the property is already animated, the specified HandoffBehavior is used. (Inherited from Animatable.) |
![]() | BeginAnimation(DependencyProperty, AnimationTimeline) | Applies an animation to the specified DependencyProperty. The animation is started when the next frame is rendered. If the specified property is already animated, the SnapshotAndReplace handoff behavior is used. (Inherited from Animatable.) |
![]() | BeginAnimation(DependencyProperty, AnimationTimeline, HandoffBehavior) | Applies an animation to the specified DependencyProperty. The animation is started when the next frame is rendered. If the specified property is already animated, the specified HandoffBehavior is used. (Inherited from Animatable.) |
![]() | CheckAccess | Determines whether the calling thread has access to this DispatcherObject. (Inherited from DispatcherObject.) |
![]() | ClearValue(DependencyProperty) | Clears the local value of a property. The property to be cleared is specified by a DependencyProperty identifier. (Inherited from DependencyObject.) |
![]() | ClearValue(DependencyPropertyKey) | Clears the local value of a read-only property. The property to be cleared is specified by a DependencyPropertyKey. (Inherited from DependencyObject.) |
![]() | Clone | Creates a modifiable clone of this DrawingBrush, making deep copies of this object's values. When copying dependency properties, this method copies resource references and data bindings (but they might no longer resolve) but not animations or their current values. |
![]() | CloneCurrentValue | Creates a modifiable clone of this DrawingBrush object, making deep copies of this object's current values. Resource references, data bindings, and animations are not copied, but their current values are. |
![]() | CoerceValue | Coerces the value of the specified dependency property. This is accomplished by invoking any CoerceValueCallback function specified in property metadata for the dependency property as it exists on the calling DependencyObject. (Inherited from DependencyObject.) |
![]() | Equals | Determines whether a provided DependencyObject is equivalent to the current DependencyObject. (Inherited from DependencyObject.) |
![]() | Freeze() | Makes the current object unmodifiable and sets its IsFrozen property to true. (Inherited from Freezable.) |
![]() | GetAnimationBaseValue | Returns the non-animated value of the specified DependencyProperty. (Inherited from Animatable.) |
![]() | GetAsFrozen | Creates a frozen copy of the Freezable, using base (non-animated) property values. Because the copy is frozen, any frozen sub-objects are copied by reference. (Inherited from Freezable.) |
![]() | GetCurrentValueAsFrozen | Creates a frozen copy of the Freezable using current property values. Because the copy is frozen, any frozen sub-objects are copied by reference. (Inherited from Freezable.) |
![]() | GetHashCode | Gets a hash code for this DependencyObject. (Inherited from DependencyObject.) |
![]() | GetLocalValueEnumerator | Creates a specialized enumerator for determining which dependency properties have locally set values on this DependencyObject. (Inherited from DependencyObject.) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | GetValue | Returns the current effective value of a dependency property on this instance of a DependencyObject. (Inherited from DependencyObject.) |
![]() | InvalidateProperty | Re-evaluates the effective value for the specified dependency property (Inherited from DependencyObject.) |
![]() | ReadLocalValue | Returns the local value of a dependency property, if it exists. (Inherited from DependencyObject.) |
![]() | SetCurrentValue | Sets the value of a dependency property without changing its value source. (Inherited from DependencyObject.) |
![]() | SetValue(DependencyProperty, Object) | Sets the local value of a dependency property, specified by its dependency property identifier. (Inherited from DependencyObject.) |
![]() | SetValue(DependencyPropertyKey, Object) | Sets the local value of a read-only dependency property, specified by the DependencyPropertyKey identifier of the dependency property. (Inherited from DependencyObject.) |
![]() | ShouldSerializeProperty | Returns a value that indicates whether serialization processes should serialize the value for the provided dependency property. (Inherited from DependencyObject.) |
![]() | ToString() | Return string representation of this Brush. (Inherited from Brush.) |
![]() | ToString(IFormatProvider) | Creates a string representation of this object based on the specified culture-specific formatting information. (Inherited from Brush.) |
![]() | VerifyAccess | Enforces that the calling thread has access to this DispatcherObject. (Inherited from DispatcherObject.) |
| Name | Description | |
|---|---|---|
![]() ![]() | IFormattable.ToString | Formats the value of the current instance using the specified format. (Inherited from Brush.) |
The following illustration shows shapes and text that were painted with a DrawingBrush.

For more information and examples, see Painting with Images, Drawings, and Visuals.
This example shows how to paint an area with a drawing. To paint an area with a drawing, you use a DrawingBrush and one or more Drawing objects. The following example uses a DrawingBrush to paint an object with a drawing of two ellipses.
<!-- Demonstrates the use of DrawingBrush. --> <Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Background="White"> <StackPanel Margin="20"> <Rectangle Width="150" Height="150" Stroke="Black" StrokeThickness="1"> <Rectangle.Fill> <DrawingBrush> <DrawingBrush.Drawing> <GeometryDrawing Brush="MediumBlue"> <GeometryDrawing.Geometry> <GeometryGroup> <EllipseGeometry RadiusX="20" RadiusY="45" Center="50,50" /> <EllipseGeometry RadiusX="45" RadiusY="20" Center="50,50" /> </GeometryGroup> </GeometryDrawing.Geometry> <GeometryDrawing.Pen> <Pen Thickness="10"> <Pen.Brush> <LinearGradientBrush> <GradientStop Offset="0.0" Color="Black" /> <GradientStop Offset="1.0" Color="Gray" /> </LinearGradientBrush> </Pen.Brush> </Pen> </GeometryDrawing.Pen> </GeometryDrawing> </DrawingBrush.Drawing> </DrawingBrush> </Rectangle.Fill> </Rectangle> </StackPanel> </Page>
using System; using System.Windows; using System.Windows.Controls; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Media.Imaging; using System.Windows.Shapes; namespace Microsoft.Samples.DrawingBrushExamples { /// <summary> /// Paints a Rectangle element with a DrawingBrush. /// </summary> public class DrawingBrushExample : Page { public DrawingBrushExample() { Background = Brushes.White; StackPanel mainPanel = new StackPanel(); // Create a drawing of two ellipses. GeometryDrawing aDrawing = new GeometryDrawing(); // Use geometries to describe two overlapping ellipses. EllipseGeometry ellipse1 = new EllipseGeometry(); ellipse1.RadiusX = 20; ellipse1.RadiusY = 45; ellipse1.Center = new Point(50, 50); EllipseGeometry ellipse2 = new EllipseGeometry(); ellipse2.RadiusX = 45; ellipse2.RadiusY = 20; ellipse2.Center = new Point(50, 50); GeometryGroup ellipses = new GeometryGroup(); ellipses.Children.Add(ellipse1); ellipses.Children.Add(ellipse2); // Add the geometry to the drawing. aDrawing.Geometry = ellipses; // Specify the drawing's fill. aDrawing.Brush = Brushes.Blue; // Specify the drawing's stroke. Pen stroke = new Pen(); stroke.Thickness = 10.0; stroke.Brush = new LinearGradientBrush( Colors.Black, Colors.Gray, new Point(0, 0), new Point(1, 1)); aDrawing.Pen = stroke; // Create a DrawingBrush DrawingBrush myDrawingBrush = new DrawingBrush(); myDrawingBrush.Drawing = aDrawing; // Create a Rectangle element. Rectangle aRectangle = new Rectangle(); aRectangle.Width = 150; aRectangle.Height = 150; aRectangle.Stroke = Brushes.Black; aRectangle.StrokeThickness = 1.0; // Use the DrawingBrush to paint the rectangle's // background. aRectangle.Fill = myDrawingBrush; mainPanel.Children.Add(aRectangle); this.Content = mainPanel; } } }
The following illustration shows the example's output.

(The center of the shape is white for reasons described in How to: Control the Fill of a Composite Shape.)
By setting a DrawingBrush object's Viewport and TileMode properties, you can create a repeating pattern. The following example paints an object with a pattern created from a drawing of two ellipses.
<!-- Demonstrates the use of DrawingBrush. --> <Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Background="White"> <StackPanel Margin="20"> <Rectangle Width="150" Height="150" Stroke="Black" StrokeThickness="1"> <Rectangle.Fill> <DrawingBrush Viewport="0,0,0.25,0.25" TileMode="Tile"> <DrawingBrush.Drawing> <GeometryDrawing Brush="MediumBlue"> <GeometryDrawing.Geometry> <GeometryGroup> <EllipseGeometry RadiusX="20" RadiusY="45" Center="50,50" /> <EllipseGeometry RadiusX="45" RadiusY="20" Center="50,50" /> </GeometryGroup> </GeometryDrawing.Geometry> <GeometryDrawing.Pen> <Pen Thickness="10"> <Pen.Brush> <LinearGradientBrush> <GradientStop Offset="0.0" Color="Black" /> <GradientStop Offset="1.0" Color="Gray" /> </LinearGradientBrush> </Pen.Brush> </Pen> </GeometryDrawing.Pen> </GeometryDrawing> </DrawingBrush.Drawing> </DrawingBrush> </Rectangle.Fill> </Rectangle> </StackPanel> </Page>
using System; using System.Windows; using System.Windows.Controls; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Media.Imaging; using System.Windows.Shapes; namespace Microsoft.Samples.DrawingBrushExamples { /// <summary> /// Paints a Rectangle element with a tiled DrawingBrush. /// </summary> public class TiledDrawingBrushExample : Page { public TiledDrawingBrushExample() { Background = Brushes.White; StackPanel mainPanel = new StackPanel(); // Create a drawing of two ellipses. GeometryDrawing aDrawing = new GeometryDrawing(); // Use geometries to describe two overlapping ellipses. EllipseGeometry ellipse1 = new EllipseGeometry(); ellipse1.RadiusX = 20; ellipse1.RadiusY = 45; ellipse1.Center = new Point(50, 50); EllipseGeometry ellipse2 = new EllipseGeometry(); ellipse2.RadiusX = 45; ellipse2.RadiusY = 20; ellipse2.Center = new Point(50, 50); GeometryGroup ellipses = new GeometryGroup(); ellipses.Children.Add(ellipse1); ellipses.Children.Add(ellipse2); // Add the geometry to the drawing. aDrawing.Geometry = ellipses; // Specify the drawing's fill. aDrawing.Brush = Brushes.Blue; // Specify the drawing's stroke. Pen stroke = new Pen(); stroke.Thickness = 10.0; stroke.Brush = new LinearGradientBrush( Colors.Black, Colors.Gray, new Point(0, 0), new Point(1, 1)); aDrawing.Pen = stroke; // Create a DrawingBrush DrawingBrush myDrawingBrush = new DrawingBrush(); myDrawingBrush.Drawing = aDrawing; // Set the DrawingBrush's Viewport and TileMode // properties so that it generates a pattern. myDrawingBrush.Viewport = new Rect(0, 0, 0.25, 0.25); myDrawingBrush.TileMode = TileMode.Tile; // Create a Rectangle element. Rectangle aRectangle = new Rectangle(); aRectangle.Width = 150; aRectangle.Height = 150; aRectangle.Stroke = Brushes.Black; aRectangle.StrokeThickness = 1.0; // Use the DrawingBrush to paint the rectangle's // background. aRectangle.Fill = myDrawingBrush; mainPanel.Children.Add(aRectangle); this.Content = mainPanel; } } }
The following illustration shows the tiled DrawingBrush output.

For more information about drawing brushes, see Painting with Images, Drawings, and Visuals. For more information about Drawing objects, see the Drawing Objects Overview.
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.







