对于一个简单的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>数据和图形属性中的字符串是相同的,但后一个示例导致异常:
无效属性值M8,4 L,12,12,12,12,4,4 Z。
我最终想要做的是将PathGeometry放入一个ResourceDictionary,并将它引用为{StaticResource},这样我就可以重用我的形状了。
编辑:
我的解决方案不是尝试用PathGeometry引用StaticResource,而是引用字符串资源。
<sys:String x:Key="TriangleShape">M 8,4 L 12,12 4,12 8,4 Z</sys:String>
...
<Path Data={StaticResource TriangleShape}" />发布于 2011-01-29 18:34:23
据我所知,Path.Data使用的路径标记语法不受PathGeometry支持。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上尝试过这个,只在我的电脑上使用Silverlight。
https://stackoverflow.com/questions/4838311
复制相似问题