WP7 路径几何错误
我在一个简单的 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>
Data 和Figures 属性中的字符串是相同的,但后一个示例会导致异常:
属性图形的属性值 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}" />
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}" />
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,路径标记语法,由 Path.Data,PathGeometry 不支持。 PathGeometry。 Figures 属性必须是 PathFigure 对象的集合。
要以这种方式指定上述形状,您可以执行如下操作:
免责声明:我还没有在 WP7 上尝试过此操作,仅在我的 PC 上的 Silverlight 上尝试过。
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:
Disclaimer: I haven't tried this on WP7, only on Silverlight on my PC.