I am looking for a way to create non-stroked regions for a StreamGeometry in xaml.
In other words, I want to know if it is possible to recreate the following code (taken from msdn) with the StreamGeometry Xaml markup syntax.
StreamGeometry geometry = new StreamGeometry();
geometry.FillRule = FillRule.EvenOdd;
using (StreamGeometryContext ctx = geometry.Open())
{
ctx.BeginFigure(new Point(10, 100), true /* is filled */, true /* is closed */);
ctx.LineTo(new Point(100, 100), false/* is not stroked */, false /* is smooth join */);
ctx.LineTo(new Point(100, 50), true /* is stroked */, false /* is smooth join */);
}
I’m looking for a solution which works in WPF since Silverlight doesn’t have a StreamGeometry.
Here is a direct translation using a PathGeometry:
This can be simplified by omitting the default values for FillRule, IsFilled, IsStroked and IsSmoothJoin, resulting in this:
This must be done with a PathGeometry, not with the geometry mini-language (eg “M10,100 L100,100 100,50”) because the mini-language provides no way to set IsStroked=false.
Since you need a StreamGeometry, I recommend you use
GeometryExtensions.DrawGeometrymethod in this answer to convert the PathGeometry defined in XAML into a StreamGeometry.I would be inclined to do this using a markup extension:
The implementation of the markup extension is trivial:
Note that this calls the GeometryExtensions.DrawGeometry extension method from the code in my earlier answer.