/// <summary>
        /// Static constructor
        /// </summary>
        static ApplicationThemeChanger()
        {
            ApplicationThemeChanger.Lock = new object();

            if (Application.Current is null)
            {
                System.Diagnostics.Trace.WriteLine($"ERROR: Cannot change the application theme because {nameof(Application)}.{nameof(Application.Current)} is null. This can happen when running unit tests.");
                return;
            }

            // Attach to the applications activated event, so that an reference to its main window can be obtained once it is available.
            Application.Current.Activated += ApplicationThemeChanger.HandleApplicationActivated;

            // Try to get a reference to the applications main window regardless of the activation event (it could have been fired already).
            ApplicationThemeChanger.MainWindow = ApplicationThemeChanger.GetMainWindow();
        }
 /// <summary>
 /// Handler for the current applications <see cref="Application.Activated"/> event.
 /// </summary>
 private static void HandleApplicationActivated(object sender, EventArgs args)
 {
     // Try to get a reference to the applications main window.
     ApplicationThemeChanger.MainWindow = ApplicationThemeChanger.GetMainWindow();
 }