This example shows how to use the TileMode property of a TileBrush to create a pattern.

The TileMode property enables you to specify how the content of a TileBrush is repeated, that is, tiled to fill an output area. To create a pattern, you set the TileMode to Tile, FlipX, FlipY, or FlipXY. You must also set the Viewport of the TileBrush so that it is smaller than the area that you are painting; otherwise, only a single tile is produced, regardless which TileMode setting you use.

<!-- Demonstrates TileMode values. --><Pagexmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:PresentationOptions="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"mc:Ignorable="PresentationOptions"Background="White"Margin="20"><Page.Resources><!-- Define a Drawing as a resource that it can be easily used
as content for all the DrawingBrush objects in this example. --><GeometryDrawingx:Key="TriangleDrawing"Geometry="M0,0 L50,0 0,50Z"Brush="#CCCCFF"PresentationOptions:Freeze="True"><GeometryDrawing.Pen><PenThickness="2"Brush="Black"MiterLimit="0"/></GeometryDrawing.Pen></GeometryDrawing></Page.Resources><StackPanelHorizontalAlignment="Left"><TextBlockMargin="0,10,0,0">None</TextBlock><RectangleWidth="50"Height="50"Stroke="Black"StrokeThickness="1"><Rectangle.Fill><!-- The DrawingBrush's content is not tiled in this example. --><DrawingBrushTileMode="None"Drawing="{StaticResource TriangleDrawing}"/></Rectangle.Fill></Rectangle><TextBlockMargin="0,10,0,0">Tile</TextBlock><RectangleWidth="50"Height="50"Stroke="Black"StrokeThickness="1"><Rectangle.Fill><!-- The DrawingBrush's content is tiled in this example.
The Viewport property is set to create four tiles. --><DrawingBrushTileMode="Tile"Viewport="0,0,0.5,0.5"Drawing="{StaticResource TriangleDrawing}"/></Rectangle.Fill></Rectangle><TextBlockMargin="0,10,0,0">FlipX</TextBlock><RectangleWidth="50"Height="50"Stroke="Black"StrokeThickness="1"><Rectangle.Fill><!-- The DrawingBrush's content is flipped horizontally as it is
tiled in this example. --><DrawingBrushTileMode="FlipX"Viewport="0,0,0.5,0.5"Drawing="{StaticResource TriangleDrawing}"/></Rectangle.Fill></Rectangle><TextBlockMargin="0,10,0,0">FlipY</TextBlock><RectangleWidth="50"Height="50"Stroke="Black"StrokeThickness="1"><Rectangle.Fill><!-- The DrawingBrush's content is flipped vertically as it is
tiled in this example. --><DrawingBrushTileMode="FlipY"Viewport="0,0,0.5,0.5"Drawing="{StaticResource TriangleDrawing}"/></Rectangle.Fill></Rectangle><TextBlockMargin="0,10,0,0">FlipXY</TextBlock><RectangleWidth="50"Height="50"Stroke="Black"StrokeThickness="1"><Rectangle.Fill><!-- The DrawingBrush's content is flipped horizontally
and vertically as it is tiled in this example. --><DrawingBrushTileMode="FlipXY"Viewport="0,0,0.5,0.5"Drawing="{StaticResource TriangleDrawing}"/></Rectangle.Fill></Rectangle></StackPanel></Page>