Back to Home
Texture background in WPF
September 15, 2011 • 5 minutes read

Seems my first blog is this. I am enjoying working with WPF. Whenever I am creating a simple or large scale application, I like to use texture backgrounds other than plane background. Becacuse it looks crispy and makes our application more beautiful. So I want to show you how to create a texture background in WPF.
Hope WPF developers are well familiar with DrawingBrush. Using Drawing Brush it is easy to create thatch backgrounds. Consider we are going to create a background which alikes Expression Blend.
Geometry Brush will contain a group of Geometry Drawings. Since the above texture contains only two colors, let me create two Geometry Drawings with rect size of 60 x 60.
<GeometryDrawing Brush="#C92F2F2F">
<GeometryDrawing.Geometry>
<GeometryGroup>
<RectangleGeometry Rect="0,0,60,60"/>
<RectangleGeometry Rect="60,60,60,60"/>
</GeometryGroup>
</GeometryDrawing.Geometry>
</GeometryDrawing>
The Brush of Geometry Drawing decides the color of rectangle. I have given the another rect with size and brush.
<GeometryDrawing Brush="#C92D2D2D">
<GeometryDrawing.Geometry>
<GeometryGroup>
<RectangleGeometry Rect="0,0,60,60"/>
<RectangleGeometry Rect="60,60,60,60"/>
</GeometryGroup>
</GeometryDrawing.Geometry>
</GeometryDrawing>
Finally the Drawing Brush looks like the one below,
<DrawingBrush x:Key="ThatchBackground" Viewport="0,0,15,15" ViewportUnits="Absolute" Stretch="None" TileMode="Tile">
<DrawingBrush.Drawing>
<DrawingGroup>
<GeometryDrawing Brush="#C92F2F2F">
<GeometryDrawing.Geometry>
<GeometryGroup>
<RectangleGeometry Rect="0,0,60,60"/>
<RectangleGeometry Rect="60,60,60,60"/>
</GeometryGroup>
</GeometryDrawing.Geometry>
</GeometryDrawing>
<GeometryDrawing Brush="#C92D2D2D">
<GeometryDrawing.Geometry>
<GeometryGroup>
<RectangleGeometry Rect="0,0,60,60"/>
<RectangleGeometry Rect="60,60,60,60"/>
</GeometryGroup>
</GeometryDrawing.Geometry>
</GeometryDrawing>
</DrawingGroup>
</DrawingBrush.Drawing>
You can use the Drawing Brush as a background of WPF objects as below,
<Grid Background="{StaticResource ThatchBackground}"/>
I like to show the screenshot of my application, where I am using this texture background.
Enjoy with WPF………..!!!!!!!!