How do I focus a modal WPF Window when the main application window is clicked

Go To StackoverFlow.com

12

I have my MainApplication Window that launches a new Window with .ShowDialog() so that it is modal.

UploadWindow uploadWindow = new UploadWindow();
uploadWindow.ShowDialog();

Now users are often leaving this window open and it can get lost under other windows. When the MainApplication is clicked you get an error-like beep and are unable to interact with it, so the modal window is blocking properly as expected, but it would be nice if the modal window was focused at this point to show the user it was still open.

Currently it just looks as if the MainApplication window has locked up.

2009-06-16 10:07
by Iain M Norman


24

Try setting the dialog's owner:

var uploadWindow = new UploadWindow();
uploadWindow.Owner = this;
uploadWindow.ShowDialog();
2009-06-16 10:16
by Matt Hamilton
Just what I was looking for - Iain M Norman 2009-06-16 10:38
I find it a little odd that the Owner property is not set by default. Thanks for the tip though, could turn out useful someday - Oskar 2009-06-16 11:09
← This. Seriously, what do you mean by this - Colonel Panic 2012-09-26 15:13
@ColonelPanic yep, this only works inside a window, not a UserControl or something else. Window.GetWindow(this) should do the trick - Salar 2014-08-10 15:43


2

I have the problem, that I can't use this, if someone have the same problem, you can use

Window.GetWindow(this)
2010-01-05 09:29
by SebastianB


1

Since I am using MVVM, I'm not creating the code from the GUI. I used this.

var uploadWindow = new UploadWindow();
uploadWindow.Owner = Application.Current.MainWindow;
uploadWindow.ShowDialog();
2016-09-02 01:40
by Donn Hardy


0

If all of the above solutions tried and still facing the same problem then here is your tested and verified solution go to your window xaml and add

ResizeMode = "NoResize"

2015-07-27 06:53
by Shahid Ullah
Does that cause the underlying modal dialog to become focussed - Iain M Norman 2015-07-28 13:18
Yes i was facing the same issue tried above all suggestions but couldn't worked for me then simply changed ResizeMode and objForm.ShowDialog(); worke - Shahid Ullah 2015-07-28 13:29
Ads