浏览代码

Fix settings not saved on system shutdown

If a session ends because a user logs off or shuts down, Closing is not raised. https://learn.microsoft.com/en-us/dotnet/api/system.windows.window.closing

Closed is used instead, but window positioning is saved on Deactivated because the window is not available for that purpose on Closed https://learn.microsoft.com/en-us/dotnet/api/system.windows.window.closed

Fixes #7
Daniel Chalmers 2 年之前
父节点
当前提交
3d8f6995fb
共有 2 个文件被更改,包括 6 次插入2 次删除
  1. 2 1
      DesktopClock/MainWindow.xaml
  2. 4 1
      DesktopClock/MainWindow.xaml.cs

+ 2 - 1
DesktopClock/MainWindow.xaml

@@ -21,7 +21,8 @@
         MouseDoubleClick="Window_MouseDoubleClick"
         MouseWheel="Window_MouseWheel"
         SourceInitialized="Window_SourceInitialized"
-        Closing="Window_Closing"
+		Deactivated="Window_Deactivated"
+		Closed="Window_Closed"
 		SizeChanged="Window_SizeChanged">
 	<Window.Resources>
 		<ContextMenu x:Key="MainContextMenu" x:Shared="False">

+ 4 - 1
DesktopClock/MainWindow.xaml.cs

@@ -265,10 +265,13 @@ public partial class MainWindow : Window
         WindowPlacementFunctions.SetPlacement(this, Settings.Default.Placement);
     }
 
-    private void Window_Closing(object sender, CancelEventArgs e)
+    private void Window_Deactivated(object sender, EventArgs e)
     {
         Settings.Default.Placement = WindowPlacementFunctions.GetPlacement(this);
+    }
 
+    private void Window_Closed(object sender, EventArgs e)
+    {
         Settings.Default.SaveIfNotModifiedExternally();
 
         App.SetRunOnStartup(Settings.Default.RunOnStartup);