Search code examples
c#wpfmessagebox

Best way to create an separate threaded MessageBox that doesn't interfere with WPF Window?


I have a Window, that has fields that let the user fill in with values, but when I show a MessageBox to tell the user that some of the fields are invalid, it prevents the user from changing from the MessageBox to the Window.

How would I create the MessageBox so that it allows the Window to be accessible while having the MessageBox? Should I multi-thread it? Is there a way to make an object like MessageBox that doesn't lock up the rest of the application?

Code:

 string unfilled = @"The following fields are mandatory and are required to continue:";
 bool invalid = false;
 foreach(Field f in _view.FormFields) {
      if(f.IsMandatory > 0 && !f.IsValid) {
           unfilled += "\n" + f.LongDisplay;
           foreach(string s in f.ErrorMessages) {
                unfilled += "\n\t" + s;
           }
           invalid = true;
      }
 }

 if(invalid) {
      MessageBox.Show(unfilled, "Invalid Submission"); <-- locks up WPF application
      return;
 }

Solution

  • The MessageBox is modal to the form it's shown from.

    As a workaround, you could always display a separate wpf form. Alternatively, you could display the error text on the form you're currently on.