Caliburn Micro cancel window close from ViewModel
Asked Answered
G

1

14

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.

Glib answered 9/1, 2012 at 15:9 Comment(0)
O
24

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
    }
}
Oruntha answered 9/1, 2012 at 15:38 Comment(1)
That's exactly what I wanted. Guess I didn't understand how to use CanClose.Glib

© 2022 - 2024 — McMap. All rights reserved.