I have a UserControl in a Window. During the lifespan of the application that Window is sometimes closed and when the user needs it again a new instance is made.
At some point the user control needs to display a dialog, and needs to pass it's parent control to that dialog as the owner.
Here's the catch. The first time the window is created and the control has to show a dialog everything works just fine. It calls Window.GetWindow(this) and passes the result to the dialog.
However, when the window is closed, and later a new instance is created and the user control opens the dialog then I get the following exception:
Cannot set Owner property to a Window that has been closed.
Whenever the Window is created this code is called
var window = new ControllerConfigurationWindow() { Owner = this };
So it's clearly a new instance, and of course while displaying the dialog, the window is open... I'm not closing it anywhere...
So I'm wondering, and it makes no sense in my mind as I say this, but could it be that Window.GetWindow(this) somehow gives me the parent of an old instance?