Caliburn Micro: DialogResult

Timm Bremus picture Timm Bremus · May 15, 2012 · Viewed 10.5k times · Source

I can't find a solution for the following problem:

I open a Dialog with the WindowManager from caliburn micro:

public void UserNew()
{
   this._windowManager.ShowDialog(new UserViewModel(this._windowManager));
}

Now I need a DialogResult when the user close the dialog with the OK button. The ShowDialog method of WindowManager don't return a DialogResult...

Can anyone help me?

Answer

Megan picture Megan · May 15, 2012

I tend to use the View Model to handle determining what happened in the dialog. For instance, you can have an IsCancelled property on your UserViewModel that you can interrogate after returning from the ShowDialog call. Something like:

public void UserNew() {
    var userViewModel = new UserViewModel(this._windowManager);
    this._windowManager.ShowDialog(userViewModel);
    if (userViewModel.IsCancelled) {
        // Handle cancellation
    } else {
        // Handle other case(s)
    }
}