Handling MessageBox in Caliburn.Micro

EisenbergEffect indicated he is injecting delegate to implement messagebox in his ongoing Caliburn.Micro application, with a very general code example:

  public delegate void ShowMessageBox(string message, string title, MessageBoxOptions options = MessageBoxOptions.Ok, Action<IMessageBox> callback = null);

In case you still don’t get the idea, here is a developer doing the exactly same thing.


My solution came up with code like this:

public class MyViewModel: Screen {
 public MyViewModel(Action<string> showMessage, Func<string, string, bool> showConfirm)
     _showMessage = showMessage;
     _showConfirm = showConfirm;

  public void Delete(){
     if (!_showConfirm("Are you very very sure to delete it?", "Confirmation")) return;
     // Do delete...
    _showMessage("Deleted as you reuqested!")
   public class HelloWp7Bootstrapper : PhoneBootstrapper
        PhoneContainer _container;

        protected override void Configure()
            _container = new PhoneContainer();

            _container.RegisterInstance(typeof(Action<string>), null, (Action<string>)(msg => MessageBox.Show(msg)));
            _container.RegisterInstance(typeof(Func<string, string, bool>), null,
                (Func<string, string, bool>)((msg, capt) => MessageBox.Show(msg, capt, MessageBoxButton.OKCancel) == MessageBoxResult.OK));


One thought on “Handling MessageBox in Caliburn.Micro

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s