Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

window

wpf

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.

like image 321
Iain M Norman Avatar asked Jun 16 '09 10:06

Iain M Norman


People also ask

Which dialog box does not prevent a user from activating other windows while it is open?

A modeless dialog box doesn't prevent a user from activating other windows while it's open.

How to show dialog in WPF?

When a modal WPF window (a window opened by calling ShowDialog) is closed, the previously activated window is reactivated. If a modal WPF window has an owner window (see Owner), the owner window is not reactivated when the modal WPF window is closed unless it was the previously activated window.

How do I open a WPF window in full screen?

Currently, the only way I know how to fullscreen my wpf application is: WindowStyle=None and WindowState=Maximized (and Topmost=True, though this is just needed to make sure it's above everything else).

How do I display a WPF window?

When a Window is created at run-time using the Window object, it is not visible by default. To make it visible, we can use Show or ShowDialog method. Show method of Window class is responsible for displaying a window.


1 Answers

Try setting the dialog's owner:

var uploadWindow = new UploadWindow();
uploadWindow.Owner = this;
uploadWindow.ShowDialog();
like image 76
Matt Hamilton Avatar answered Sep 25 '22 17:09

Matt Hamilton