在 inkcanavas 中选择元素后如何复制它们

发布于 2024-11-17 17:15:02 字数 235 浏览 7 评论 0原文

我尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

与风相奔跑 2024-11-24 17:15:02

您可以使用 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文