Wouter
Wouter

Reputation: 2262

How can I reparent a WPF UIElement?

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.

Upvotes: 0

Views: 1511

Answers (1)

Fatema
Fatema

Reputation: 135

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.

Upvotes: 1

Related Questions