I'm currently implementing a MessageDialog control. It is there to replace MessageBox
entirely and is displayed as an "in-window popup" (correct UX term needed).
Currently, its constructor is private and there is a method Show
, just like in MessageBox.Show
. However, MessageBox
blocks the UI thread and returns a result.
What my MessageDialog
control currently does is having a Action<MessageDialogResult> callback
parameter which gets called when a button is clicked.
Utilizing MessageDialog
// class MessageDialog
public static void MessageDialog.Confirmation(Window owner, string message, Action<MessageDialogResult> callback);
// When used by other controls
MessageDialog.Confirmation(WindowMain.Singleton, true, (result) =>
{
if (result.Button == MessageDialogButton.Yes)
{
//...
}
});
However, having a callback instead of a blocking method call like in MessageBox.Show
yields absolutely no benefits for me. It makes things rather complicated. What I'm rather trying to achieve is something like...
if (MessageDialog.Confirmation(WindowMain.Singleton, true).Button == MessageDialogButton.Yes)
{
//...
}
... which is much cleaner in my opinion.
The current code behind is basically
- Create instance of
MessageDialog
and populate content with text - Add it to the children of
Window.Content.Children
- On button click, call
callback(result)
and remove fromWindow.Content.Children
The question: What I would like to achieve is having a blocking method call instead of one that triggers a callback.
How about something like this: