将几何/路径转换为迷你语言字符串?
追踪如何以编程方式将路径字符串转换为 WPF 中的路径对象并不难,但是是否有内置函数可以将几何图形或路径转换回迷你语言中的字符串?
It's not too hard to track down how to programmatically convert path strings into path objects in WPF, but is there a built-in function to convert a geometry or path back to a string in the mini-language?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编辑:刚才看到这个,我认为应该有一个名为
GeometryConverter
应该能够做到这一点,而且确实有。只需创建其中之一并使用ConvertToString
位于要转换的几何图形上。您可以使用
XamlWriter
类来输出对象作为 XAML,几何图形将自动简化为迷你语言。例如,如果这是您的输入:
...并且您将其序列化...
...您将得到以下内容:
所有
PathGeometry
现在均采用迷你语言。如果您想立即在应用程序中使用它,我想您可以将其写入MemoryStream
并通过创建XmlDocument
从中获取数据。Edit: Looking at this just now i thought that there should be a class called
GeometryConverter
which should be able to do this, and indeed there is. Just create one of those and useConvertToString
on the geometry you want to convert.You can use the
XamlWriter
class to output objects as XAML, geometry will automatically be reduced to the mini-language.e.g. if this is your input:
...and you serialize it...
...you get the following:
All the
PathGeometry
is now in mini-language. If you want to use this right away in your application i suppose you could write it to aMemoryStream
and get the data from it by creating aXmlDocument
from it.