Owner window lost focus
-
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?
All Replies
-
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
Hi olelar
I think that you can set Owner to null of the child window first before close it in Deactivate event. For example,
Code Blockprivate void Window_Deactivated(object sender, EventArgs e)
{
this.Owner = null;
Close();
}
Best Regards,
Wei Zhou
-
Tuesday, June 10, 2008 6:07 PM
In the Unload event, set focus to owner window, like this:
public void OnUnloaded(object sender, RoutedEventArgs e) { try { // opacar ventana this.Owner.Opacity = 1.0; // habilitar ventana this.Owner.IsEnabled = true; // enfocar owner this.Owner.Focus(); } catch (Exception ex) { // error AppManagement.MessageError(ex); } }
saludos !! -
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)

