Thursday, December 06, 2007 9:08 AM
I got a main window and a child window. the child window is set owner = main window. If i close the child window, the main window looses its focus and if i got ex. Explorer in background it comes in front instead of main window.
Looks like this only happens if Explorer is maximized...
Closeing of child window happens on window.deactivated.
The reason that i use owner is because i dont want my child window visible in tab+alt menu.
Anyone know why this happens or know a other way to hide windows from the alt+tab menu?
Thursday, December 06, 2007 3:02 PM
Sry for bump, hope someone can give me a answer
Friday, December 07, 2007 3:57 AM
"Closeing of child window happens on window.deactivated."
Do you mean you call childWindow.Close() when the child window is deactivated or the owner is? Would you please post your code snipet? Thanks
Tuesday, December 11, 2007 10:10 AMModerator
I think that you can set Owner to null of the child window first before close it in Deactivate event. For example,Code Block
private void Window_Deactivated(object sender, EventArgs e)
this.Owner = null;
Tuesday, June 10, 2008 6:07 PMIn the Unload event, set focus to owner window, like this:
Tuesday, September 30, 2008 6:40 PMI know this is an old thread, but as a side note, I think I have a hunch about what is happening based on my own experience with the problem (and this fix to it -- thank you, Wei!) If I do not bring up a child window from the window I am closing, it closes fine without bringing up what appears to be the root-most window to the front. If I had ever brought up a modal child window from the window I'm closing, however, it seems to break the connection between the parent window and the owner of the parent window. The model dialog may be breaking the owner of the parent window when it comes up.Again, this is just a hunch, but I know this fix works and, again, thank you Wei!
Friday, December 24, 2010 11:15 AM
The same thing in WPF 4.0. It's very bad that such old bug wasn't fixed since 2007.
MainWindow opens ChildWindow and sets its Owner property to MainWindow. ChildWindow calls MessageBox.Show(...). After that i close MessageBox, close CHildWindow and MainWindow gets deactivated (any other window are over MainWindow)