Reputation: 89
I want to draw a shape, that will be a rectangle with many circle holes. It should looks a little bit like Connect four game board. I was wondering whether is it possible to draw it without any code-behind helpers or loops.
So far I have done single element:
<Canvas>
<Path Fill="Red">
<Path.Data>
<CombinedGeometry GeometryCombineMode="Xor">
<CombinedGeometry.Geometry1>
<RectangleGeometry Rect="0, 0, 60, 60" />
</CombinedGeometry.Geometry1>
<CombinedGeometry.Geometry2>
<EllipseGeometry RadiusX="25" RadiusY="25" Center="30,30" />
</CombinedGeometry.Geometry2>
</CombinedGeometry>
</Path.Data>
</Path>
</Canvas>
Is it possible to multiple this element only in XAML?
Upvotes: 2
Views: 563
Reputation: 966
You can use VisualBrush
as background for the Canvas
and specify your geometry as visual of the brush. Here is an example:
<Canvas Width="200" Height="200">
<Canvas.Background>
<VisualBrush TileMode="Tile" Stretch="None" Viewport="0,0,0.35,0.35">
<VisualBrush.Visual>
<Path Fill="Red">
<Path.Data>
<CombinedGeometry GeometryCombineMode="Xor">
<CombinedGeometry.Geometry1>
<RectangleGeometry Rect="0, 0, 60, 60" />
</CombinedGeometry.Geometry1>
<CombinedGeometry.Geometry2>
<EllipseGeometry RadiusX="25" RadiusY="25" Center="30,30" />
</CombinedGeometry.Geometry2>
</CombinedGeometry>
</Path.Data>
</Path>
</VisualBrush.Visual>
</VisualBrush>
</Canvas.Background>
</Canvas>
Upvotes: 2