Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Caliburn Micro cancel window close from ViewModel

When the user clicks the close button of a Window, is it possible to cancel the close from the ViewModel or do I have to resort to code behind?

From what I can tell, CanClose or TryClose doesn't do the trick.

like image 222
Kristoffer Lindvall Avatar asked Jan 09 '12 15:01

Kristoffer Lindvall


1 Answers

You may have already tried this but I've just created a quick test, deriving a view model from Screen and overriding CanClose.

public class ShellViewModel : Screen
{
    public override void CanClose(Action<bool> callback)
    {
        //if(some logic...)
        callback(false); // will cancel close
    }
}
like image 98
ChrisWay Avatar answered Oct 20 '22 04:10

ChrisWay