I was able to create stripe patterns in WPF, but how can I create a pattern like this in XAML? Is there a default similar brush for this in WPF?
Create a hatch pattern in WPF
13.8k Views Asked by Vahid At
2
There are 2 best solutions below
3

Here's another approach, for a different style of hatching:
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:po="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options"
Background="Black">
<Page.Resources>
<VisualBrush x:Key="HatchBrush" TileMode="Tile"
Viewport="0,0,5,5" ViewportUnits="Absolute"
Viewbox="0,0,5,5" ViewboxUnits="Absolute"
po:Freeze="True">
<VisualBrush.Visual>
<Path Data="M 0 5 L 5 0 M -2 2 L 2 -2 M 3 7 L 7 3"
Stroke="#80ffffff" StrokeEndLineCap="Square"
RenderOptions.EdgeMode="Aliased" />
</VisualBrush.Visual>
</VisualBrush>
</Page.Resources>
<Grid Background="{StaticResource HatchBrush}" />
</Page>
You can do it in XAML using
VisualBrush
. You only need to specify Data values for thePath
, for example:XAML
Output
For converting
Image
to Vector graphics (Path) useInkscape
, which is free and very useful. For more information see this link:Vectorize Bitmaps to XAML using Potrace and Inkscape
Edit
For better performance, you may
Freeze()
you Brushes with help ofPresentationOptions
like this:Quote from
MSDN
: