Handling MessageBox in Caliburn.Micro
November 18, 2010
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));
...
No comments yet





