From the documentation to MessageBox
class:
Message boxes always have an owner window. By default, the owner of a message box is the window that is currently active in an application at the time that a message box is opened. However, you can specify another owner for the Window
by using one of several Show
overloads. For more information about owner windows, see Window.Owner
.
Thus your problem is really similar to this question where the application exists before message box is dismissed by the user.
The first thing to try is to pass null
as Window
parameter.
MessageBox.Show(null, ex.Message, "Error", MessageBoxButton.OK);
If you have an instance of Window
class, for example your main window object, pass it instead of null
:
MessageBox.Show(mainWindow, ex.Message, "Error", MessageBoxButton.OK);
If you are currently in any of the main window methods, you can pass this
as the Window:
MessageBox.Show(this, ex.Message, "Error", MessageBoxButton.OK);
Use null
only in case where there's no main window object available at this time.
Look at MessageBox sample. You should be able to see the difference between the cases where this
is passed as the owner window and where null
is passed.