XAML DrawingBrush
A Drawing Brush can be used to paint an area with shapes, text, images, and even video. This article shows how to use DrawingBrush element in XAML.
Drawing Brush is a new addition to the brush types since GDI+. A Drawing Brush can be used to paint an area with shapes, text, images, and even video. The <DrawingBrush/> represents the drawing brush in XAML. A Drawing Brush uses drawing objects GeomertyDrawing, ImageDrawing, VideoDrawing, and GylphRunDrawing to draw shapes, images, video, and text respectively.
The following code uses a DrawingBrush to fill two ellipses. I will cover DrawingBrush objects, its methods and properties in more details in my seperate article.
<Rectangle Width="300" Height="300" Stroke="Black" StrokeThickness="2">
<Rectangle.Fill>
<DrawingBrush>
<DrawingBrush.Drawing>
<GeometryDrawing Brush="Green">
<GeometryDrawing.Geometry>
<GeometryGroup>
<EllipseGeometry RadiusX="0.1" RadiusY="0.5" Center="0.5,0.5" />
<EllipseGeometry RadiusX="0.5" RadiusY="0.1" Center="0.5,0.5" />
</GeometryGroup>
</GeometryDrawing.Geometry>
</GeometryDrawing>
</DrawingBrush.Drawing>
</DrawingBrush>
</Rectangle.Fill>
</Rectangle>
|
The output looks like Figure 1.
Figure 1. Rectangle filled with a drawing brush
Further Readings
You may also want to read these related articles.
Ask Your Question
Got a programming related question? You may want to post your question here