WPG PathGeometry Error

I have a strange error with a simple PathGeometry object, and I cannot figure out how to figure it out. I would appreciate it if someone could explain to me why this is not working.

Here is an example of a work path that 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 doesn't 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 line in the data and picture properties is identical, but the last example throws an exception:

Invalid attribute value M 8.4 L 12.12 4.12 8.4 Z for a property.

Ultimately, I would like to make PathGeometry in a ResourceDictionary and specify it as {StaticResource} so that I can reuse my shapes.

Edit:

My solution was to instead of referencing a PathGeometry to a StaticResource instead of referencing 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}" /> 
+6
path windows-phone-7 silverlight pathgeometry
source share
1 answer

From what I can tell, the path markup syntax used by Path.Data is not supported by PathGeometry. The PathGeometry.Figures property should instead be a collection of PathFigure objects.

To specify the above form in this way, you can 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 have not tried this on WP7, only on Silverlight on my PC.

+4
source share

All Articles