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

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:


Leave a Reply

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

You are commenting using your 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