Use ShowDialog instead of the Show method to pop up a message box window. Thus, the user will first close the pop-up or message box before returning to the main window
MessageWindow message= new MessageWindow(); message.ShowDialog();
Edit
You obviously would like to return the result in the main windows? You can do this in several ways. The easiest way is to open a public method in MainWindow
public GetResult(bool result) {
Create a MessageWindow constructor that takes a MainWindow in the parameter
private MainWindow window; public MessageWindow(MainWindow mainWindow) { InitializeComponent(); window = mainWindow; } //now handle the click event of yes and no button private void YesButton_Click(object sender, RoutedEventArgs e) { //close this window this.Close(); //pass true in case of yes window.GetResult(true); } private void NoButton_Click_1(object sender, RoutedEventArgs e) { //close this window this.Close(); //pass false in case of no window.GetResult(false); } //in that case you will show the popup window like this MessageWindow message= new MessageWindow(this); message.ShowDialog();
source share