How to make main window wait until a newly opened window closes in C# WPF? How to make main window wait until a newly opened window closes in C# WPF? windows windows

How to make main window wait until a newly opened window closes in C# WPF?


Use ShowDialog instead of Show -

Win.ShowDialog();

From MSDN -

Opens a window and returns only when the newly opened window is closed.


Use ShowDialog() method as it Opens a window and returns only when the newly opened window is closed.

syntax

Win.ShowDialog();


Although ShowDialog works fine, you may set MainWindow.IsEnabled = false if you don't like that modal window. Sometimes it's useful to see the main window.