开发者

How can I reparent a WPF UIElement?

开发者 https://www.devze.com 2023-01-23 01:41 出处:网络
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

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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号