SNIPPET: Prevent unwanted window close in Caliburn.Micro

I needed to avoid an unwanted Window close (using the [X] button in top right of Window).

The window is a UserControl inheriting the Caliburn.Micro Screen class (which is needed to provide the functionality).

public override void CanClose(Action<bool> callback)
{ // Prevents closing of window using the [X] button
     callback(_userExit); 
}

Simply override the Screen CanClose method.

_userExit is a private bool that is set in the code. Initialised to false and only set true if the user cicks the one button that is intended to close the window.

Method found on StackOverflow: http://stackoverflow.com/questions/8790526/caliburn-micro-cancel-window-close-from-viewmodel

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s