Cancelling Window close in WPF

In this post we will avoid a window to be closed.

Forms in .NET 2.0 have the Closing event and this event has the e parameter of type ClosingEventArgs.

ClosingEventArgs has the Cancel property that if set to True will cancel the close procedure.

Visual Studio 2008 SP1 when used with a WPF project will generate an e parameter of type EventArgs. Just changing the type to ClosingEventArgs will do the job.