I'm having a strange error with a simple PathGeometry object and I can't seem to figure it out. I would appreciate it if someone could explain to me why this doesn't work.
Here is an example of a working Path, which draws a small triangle:
<Path Data="M 8,4 L 12,12 4,12 8,4 Z" Stroke="White" />
Here is an example of a Path that does not seem to work for me:
<Path Stroke="White">
<Path.Data>
<PathGeometry Figures="M 8,4 L 12,12 4,12 8,4 Z" />
</Path.Data>
</Path>
The string in the Data and Figures properties are identical, yet the latter example results in the exception:
Invalid attribute value M 8,4 L 12,12 4,12 8,4 Z for property Figures.
What I would like to do ultimately is to put the PathGeometry into a ResourceDictionary and reference it as a {StaticResource} so I can re-use my shapes.
Edit:
My solution was to instead of trying to reference a PathGeometry with a StaticResource, to instead reference a string resource.
<sys:String x:Key="TriangleShape">M 8,4 L 12,12 4,12 8,4 Z</sys:String>
...
<Path Data={StaticResource TriangleShape}" />
From what I can tell, path markup syntax, as used by Path.Data, isn't supported by PathGeometry. The PathGeometry.Figures property has to be a collection of PathFigure objects instead.
To specify the above shape in this way, you could do something like the following:
<Path Stroke="White">
<Path.Data>
<PathGeometry>
<PathGeometry.Figures>
<PathFigure StartPoint="8,4">
<PathFigure.Segments>
<LineSegment Point="12,12" />
<LineSegment Point="4,12" />
<LineSegment Point="8,4" />
</PathFigure.Segments>
</PathFigure>
</PathGeometry.Figures>
</PathGeometry>
</Path.Data>
</Path>
Disclaimer: I haven't tried this on WP7, only on Silverlight on my PC.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With