I am writing an application (c# + wpf) where all modal style dialogs are implemented as a UserControl on top of a translucent grid covering the main window. This means there is only one window and it maintains the look and feel of all the firms applications.
To show a message box, the syntax is as following:
CustomMessageBox b = new CustomMessageBox("hello world");
c.DialogClosed += ()=>
{
// the rest of the function
}
// this raises an event listened for by the main window view model,
// displaying the message box and greying out the rest of the program.
base.ShowMessageBox(b);
As you can see, not only is the flow of execution actually inverted, but its horribly verbose compared to the classic .NET version:
MessageBox.Show("hello world");
// the rest of the function
What I am really looking for is a way to not return from base.ShowMessageBox until the dialog closed event has been raised by it, but I cant see how it is possible to wait for this without hanging the GUI thread and thus preventing the user ever clicking OK. I am aware I can take a delegate function as a parameter to the ShowMessageBox function which kind of prevents the inversion of execution, but still causes some crazy syntax/indenting.
Am I missing something obvious or is there a standard way to do this?