Is there a way to know if a WPF application is shutting down?

    /// <summary>
    /// Hack to check if the application is shutting down.
    /// </summary>
    public static bool IsShuttingDown()
    {
        try
        {
            Application.Current.ShutdownMode = Application.Current.ShutdownMode;
            return false;
        }
        catch (Exception)
        {
            return true;
        }
    }

There is Application.Exit event, you should be able to do with that.

If you really need it to be a property, then create a property into your App class (your class inheriting Windows.Application) and set it to true in with the Application.Exit event.

Tags:

Wpf