I'm running into a problem with WPF and PathGeometry. I have the following Path object which is a combination of lines and arcs.
<Path Data="M100,180L220,180 M220,180L220,152 M220,152L217,150
M217,150L182,150 M180,147L180,132 M182,130L217,130 M217,130L220,127
M220,127L220,80 M220,80L100,80 M100,80L100,180 M182,150L180,147
M180,132L182,130">
Here's a simple code snippet that should draw the entire shape.
private void DrawIt()
{
Canvas canv = new Canvas();
this.Content = canv;
canv.Margin = new Thickness(0, 0, 0, 0);
canv.Background = new SolidColorBrush(Colors.White);
Path testPath = GetPath("blue");
testPath.Data = Geometry.Parse("M100,180L220,180 M220,180L220,152 M220,152L217,150 M217,150L182,150 M180,147L180,132 M182,130L217,130 M217,130L220,127 M220,127L220,80 M220,80L100,80 M100,80L100,180 M182,150L180,147 M180,132L182,130 ");
var area = testPath.Data.GetArea();
canv.Children.Add(testPath);
this.Content = canv;
}
private Path GetPath(string aColor)
{
Path imagePath = new Path();
SolidColorBrush colorBrush = (SolidColorBrush)new BrushConverter().ConvertFromString(aColor);
imagePath.Stroke = colorBrush;
imagePath.StrokeThickness = 2;
imagePath.Fill = colorBrush;
return imagePath;
}
The code above results in the following image:
My problem is that I'm trying to get the area of this image, but Path.Data.GetArea() only ever returns 0.0.
Any help would be appreciated.