在 inkcanavas 中选择元素后如何复制它们
我尝试使用 Inkcanvas.copy()
和 Inkcanvas.Paste()
但失败了,所以我将元素保存在列表中,然后尝试将它们作为子元素再次添加到inkcanvas
但我收到异常错误
指定的视觉对象已经是以下对象的子对象 另一个视觉或一个的根 组合目标。
那我该怎么办?
I tried to use Inkcanvas.copy()
and Inkcanvas.Paste()
but it failed so I save the elements in list and then tried to add them again as a child in the inkcanvas
but I got exception error
Specified Visual is already a child of
another Visual or the root of a
CompositionTarget.
so what should I do ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 XamlWriter.Save 序列化所选元素(复制时),并使用 XamlReader.Load 反序列化/加载(粘贴时)。但是使用 XamlReader/XamlWriter 进行序列化和反序列化存在一些问题,您必须处理这些问题(您可以在 SO 和 Web 上找到很多有关此问题的帮助)。
您可以查看这篇文章,其中介绍了自定义画布的实现 -
WPF 图表设计器 - 第 4 部分
You can serialize the selected element(when copying) using XamlWriter.Save, and de-serialize/load(when Pasting) using XamlReader.Load. But there are issues with serializing and de-serializing using XamlReader/XamlWriter which you will have to take care of(you can find a lot of help regarding that on SO and web).
You can have a look at this article having this implementation for Custom Canvas -
WPF Diagram Designer - Part 4