我对一个简单的PathGeometry对象有一个奇怪的错误,我似乎无法搞清楚。如果有人能向我解释为什么这不起作用,我将不胜感激。
这是一个工作路径的示例,它绘制一个小三角形:
<Path Data="M 8,4 L 12,12 4,12 8,4 Z" Stroke="White" />
以下是一个似乎对我不起作用的路径示例:
<Path Stroke="White">
<Path.Data>
<PathGeometry Figures="M 8,4 L 12,12 4,12 8,4 Z" />
</Path.Data>
</Path>
“数据”和“数字”属性中的字符串相同,但后一个示例导致异常:
无效属性值M 8,4 L 12,12 4,12 8,4 Z属性数字。
我最想做的是将PathGeometry放入ResourceDictionary并将其引用为{StaticResource},以便我可以重复使用我的形状。
修改
我的解决方案是尝试使用StaticResource引用PathGeometry,而不是引用字符串资源。
<sys:String x:Key="TriangleShape">M 8,4 L 12,12 4,12 8,4 Z</sys:String>
...
<Path Data={StaticResource TriangleShape}" />
答案 0 :(得分:4)
据我所知,PathGeometry不支持Path.Data使用的路径标记语法。 PathGeometry.Figures属性必须是PathFigure对象的集合。
要以这种方式指定上述形状,您可以执行以下操作:
<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>
免责声明:我没有在WP7上试过这个,只在我PC上的Silverlight上试过。