GeometryDrawing序列化/反序列化
需要为由 GeometryDrawings 形成的动态生成的样式提供某种接口(保存/编辑/加载)。问题是在它们缺乏 Name 属性的情况下它们之间的区别。我尝试过这样的事情:
// some dummy predefined style, it has more drawings but i keep first one
const string templateXaml = @"<DrawingBrush xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" Stretch=""Uniform"">
<DrawingBrush.Drawing>
<DrawingGroup>
<DrawingGroup.Children>
<GeometryDrawing Geometry=""F1 M 77,92L 704,92L 704,517L 77,517L 77,92 Z "" x:Name=""test_name"">
<GeometryDrawing.Pen>
<Pen Thickness=""4"" LineJoin=""Round"" Brush=""#FFFF7D00""/>
</GeometryDrawing.Pen>
</GeometryDrawing>
<!--More drawings here -->
</DrawingGroup.Children>
</DrawingGroup>
</DrawingBrush.Drawing>
</DrawingBrush>";
var drawingBrush = XamlReader.Parse(templateXaml) as DrawingBrush;
var firstDrawing = (drawingBrush.Drawing as DrawingGroup).Children[0] as GeometryDrawing;
//..
var name = firstDrawing.GetValue(NameProperty);
//..
firstDrawing.SetValue(FrameworkElement.NameProperty, "some value");
我希望在名称变量(或类似的东西)中包含 x:Name 以便能够更改它,然后序列化以获得例如相同的样式但具有不同名称的绘图(现在的情况是它们被命名为 Element1,2,3...,并且必须根据主题领域进行命名,并且处理必须是自动的,而不是手动的,因为事实上没有能力做到所见即所得 -每张图纸都放入视觉中,视觉是放入自定义 FrameworkElement 等)。当然,使用图纸的整个过程很痛苦,但这是我不能忽视的系统设计要求。提前致谢。
There is a need to provide some sort of interface(save/edit/load) to dynamically generated styles that are formed from GeometryDrawings. The problem is distinction between them in situation they lack Name property. I've tried something like this :
// some dummy predefined style, it has more drawings but i keep first one
const string templateXaml = @"<DrawingBrush xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" Stretch=""Uniform"">
<DrawingBrush.Drawing>
<DrawingGroup>
<DrawingGroup.Children>
<GeometryDrawing Geometry=""F1 M 77,92L 704,92L 704,517L 77,517L 77,92 Z "" x:Name=""test_name"">
<GeometryDrawing.Pen>
<Pen Thickness=""4"" LineJoin=""Round"" Brush=""#FFFF7D00""/>
</GeometryDrawing.Pen>
</GeometryDrawing>
<!--More drawings here -->
</DrawingGroup.Children>
</DrawingGroup>
</DrawingBrush.Drawing>
</DrawingBrush>";
var drawingBrush = XamlReader.Parse(templateXaml) as DrawingBrush;
var firstDrawing = (drawingBrush.Drawing as DrawingGroup).Children[0] as GeometryDrawing;
//..
var name = firstDrawing.GetValue(NameProperty);
//..
firstDrawing.SetValue(FrameworkElement.NameProperty, "some value");
I would like to have x:Name here in name variable (or something like this) to be able to change it and than serialize to get, for example, the same style but with different names for drawings (case is now they are named Element1,2,3..., and have to be named according to subject area, and that processing have to be automatic but not manual regarding the fact there is no ability to WYSIWYG'ly do that - each Drawing is put into Visual, Visuals are put into custom FrameworkElement etc.). Of course, the whole process of working with Drawings is a pain, but that is a system design requirement i can't ignore. Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有找到比将绘图包装在 BL 类中并序列化/反序列化更好的方法。失去了一致性并违反了一点要求 - 现在我有两个代表图形对象的实体(简单的几何图形和描述它们的类),但它们可以在需要时进行转换/交换。
Didn't find better way than wrap drawings in BL classes and serialize/deserialize them. Lost consistency and violated requirements a bit - now i have two entities (plain geometries and classes that describes them) representing graphical objects, but they can be converted/interchanged when needed.