I\'m making a small demo application for MVVM with caliburn.
Now I want to show a MessageBox
, but the MVVM way.
For dialogs I created an event, that
As you mentioned, you just prepare the view model (e.g. ConfirmationBoxViewModel
) and an appropriate view. You'll have to create two actions (after inheriting the view model from Screen
, which is necessary to use TryClose
. You can always implement IScreen
instead, but that would be more work):
public void OK()
{
TryClose(true);
}
public void Cancel()
{
TryClose(false);
}
and then in your other view model:
var box = new ConfirmationBoxViewModel()
var result = WindowManager.ShowDialog(box);
if(result == true)
{
// OK was clicked
}
Notice that after the dialog closes, you can access the view model properties if you need to pull additional data from the dialog (e.g. Selected item, display name etc).