How to close dialog window from viewmodel (Caliburn+WPF)?

Witcher picture Witcher · Apr 10, 2012 · Viewed 16.9k times · Source

I haveViewModel1 and View1 associated with it. I start dialog window from ViewModel2 (some another viewmodel) using IWindowManager object. The code from ViewModel2 class:

windowManager.ShowDialog(new ViewModel());

So, I have Dialog Window with View1 user control.

My answer is next - I can close that dialog window using red close button, but how to close it using my specific button (contained in View1 user control), something like "Cancel" button with close command (Command={Binding CancelCommand}), CancelCommand of course is contained in ViewModel1 class.

Answer

Michal T picture Michal T · Jul 19, 2012

It's even easier if your view model extends Caliburn.Micro.Screen:

TryClose();