lundi 29 juin 2015

Bring MainWindow to front, not always on top, and wait for it to close

I have a WPF application with a single window. When the application starts, I want to bring it to the front. I also want to let the user move other windows on top of it (it shouldn't be always on top), and I want to wait for the window to close in code. Perhaps I am being too picky as WPF does not appear to support this.

Currently, I have this:

MainWindow.Topmost = true;
MainWindow.Show();
MainWindow.Activate();
MainWindow.Topmost = false;
MainWindow.Focus();

It's great except that MainWindow.Show() returns immediately and execution resumes. In the past, we were using

MainWindow.TopMost = true;
MainWindow.ShowDialog();

But then this window is always on top and obstructs all other windows (not the best user experience). Are there any other options? Please feel free to suggest I am architecting this incorrectly as well. Thank you!

Aucun commentaire:

Enregistrer un commentaire