如何重新设置 WPF UIElement 的父级?

发布于 2024-09-30 09:55:15 字数 365 浏览 1 评论 0原文

如何将 UIElement 重新设置为另一个窗口的父级?在关闭窗口之前,我已将 Content 设置为 null。然后,启动一个新窗口,并将 UIElement 设置为该窗口的内容。

这给出了 InvalidOperationException:“Het opgegeven element is al het logische onderliggende element van een ander element.Koppel dit eerst los。”

不幸的是我的窗户是荷兰语的。粗略翻译如下:“指定的元素已经是另一个元素的逻辑子元素。先断开它。”

我不明白的是我已经将它解耦了,但它仍然给出了这个错误。

How can I reparent an UIElement to another Window? I have set Content to null prior to closing the Window. Afterwards a new Window is started and the UIElement is set to the Content of that Window.

This gives an InvalidOperationException: "Het opgegeven element is al het logische onderliggende element van een ander element. Koppel dit eerst los."

Unfortunately my windows is dutch. The rough translation is as follows: "The specified element is already the logical child element of another element. Disconnect it first."

The thing I don't understand is that I have decoupled it, but still it gives this error.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

小耗子 2024-10-07 09:55:15

仅将内容设为空不会影响父子关系。您需要使用窗口的RemoveLogicalChild函数来删除作为前一个窗口的子级的UIElement,然后将其附加到新窗口。

Just making the content null will not effect the parent child relation ship. You need to use RemoveLogicalChild function of window to remove the UIElement as child of the previous window and then attach it to new window.

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