Applies a DrawingBrush and DrawingGroup to draw gridlines as a background of a Grid control.
<Window x:Class="DrawingBrushGridline"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Drawing Brush - Gridline" Height="300" Width="300">
<Grid>
<Grid.Background>
<DrawingBrush Viewport="0,0,50,50" ViewportUnits="Absolute"
TileMode="Tile">
<DrawingBrush.Drawing>
<DrawingGroup>
<DrawingGroup.Children>
<GeometryDrawing Geometry="M0,0 L50,0">
<GeometryDrawing.Pen>
<Pen Thickness="2"
Brush="LightGreen" />
</GeometryDrawing.Pen>
</GeometryDrawing>
<GeometryDrawing Geometry="M0,10 L50,10">
<GeometryDrawing.Pen>
<Pen Thickness="1"
Brush="LightGreen" />
</GeometryDrawing.Pen>
</GeometryDrawing>
<GeometryDrawing Geometry="M0,20 L50,20">
<GeometryDrawing.Pen>
<Pen Thickness="1"
Brush="LightGreen" />
</GeometryDrawing.Pen>
</GeometryDrawing>
<GeometryDrawing Geometry="M0,30 L50,30">
<GeometryDrawing.Pen>
<Pen Thickness="1"
Brush="LightGreen" />
</GeometryDrawing.Pen>
</GeometryDrawing>
<GeometryDrawing Geometry="M0,40 L50,40">
<GeometryDrawing.Pen>
<Pen Thickness="1"
Brush="LightGreen" />
</GeometryDrawing.Pen>
</GeometryDrawing>
<GeometryDrawing Geometry="M0,0 L0,50">
<GeometryDrawing.Pen>
<Pen Thickness="2"
Brush="LightGreen" />
</GeometryDrawing.Pen>
</GeometryDrawing>
<GeometryDrawing Geometry="M10,0 L10,50">
<GeometryDrawing.Pen>
<Pen Thickness="1"
Brush="LightGreen" />
</GeometryDrawing.Pen>
</GeometryDrawing>
<GeometryDrawing Geometry="M20,0 L20,50">
<GeometryDrawing.Pen>
<Pen Thickness="1"
Brush="LightGreen" />
</GeometryDrawing.Pen>
</GeometryDrawing>
<GeometryDrawing Geometry="M30,0 L30,50">
<GeometryDrawing.Pen>
<Pen Thickness="1"
Brush="LightGreen" />
</GeometryDrawing.Pen>
</GeometryDrawing>
<GeometryDrawing Geometry="M40,0 L40,50">
<GeometryDrawing.Pen>
<Pen Thickness="1"
Brush="LightGreen" />
</GeometryDrawing.Pen>
</GeometryDrawing>
</DrawingGroup.Children>
</DrawingGroup>
</DrawingBrush.Drawing>
</DrawingBrush>
</Grid.Background>
</Grid>
</Window>
Related examples in the same category