浏览代码

Fix wrong position when restoring window by fixing timing issue #227

Ruben 3 月之前
父节点
当前提交
a7e4131585
共有 1 个文件被更改,包括 7 次插入3 次删除
  1. 7 3
      src/PicView.Avalonia.Win32/WindowImpl/Win32Window.cs

+ 7 - 3
src/PicView.Avalonia.Win32/WindowImpl/Win32Window.cs

@@ -15,6 +15,7 @@ public static class Win32Window
     public static async Task Fullscreen(Window window, MainViewModel vm, bool saveSettings = true)
     public static async Task Fullscreen(Window window, MainViewModel vm, bool saveSettings = true)
     {
     {
         IsChangingWindowState = true;
         IsChangingWindowState = true;
+        
         // Save window size, so that restoring it will return to the same size and position
         // Save window size, so that restoring it will return to the same size and position
         WindowResizing.SaveSize(window);
         WindowResizing.SaveSize(window);
 
 
@@ -45,7 +46,8 @@ public static class Win32Window
         // Fixes https://github.com/Ruben2776/PicView/issues/226
         // Fixes https://github.com/Ruben2776/PicView/issues/226
         await WindowFunctions.ResizeAndFixRenderingError(vm);
         await WindowFunctions.ResizeAndFixRenderingError(vm);
 
 
-        IsChangingWindowState = false;
+        Dispatcher.UIThread.Post(() => IsChangingWindowState = false, DispatcherPriority.Background);
+
 
 
         if (saveSettings)
         if (saveSettings)
         {
         {
@@ -80,7 +82,8 @@ public static class Win32Window
         vm.MainWindow.IsFullscreen.Value = false;
         vm.MainWindow.IsFullscreen.Value = false;
         vm.MainWindow.CanResize.Value = false;
         vm.MainWindow.CanResize.Value = false;
 
 
-        IsChangingWindowState = false;
+        Dispatcher.UIThread.Post(() => IsChangingWindowState = false, DispatcherPriority.Background);
+
         if (saveSettings)
         if (saveSettings)
         {
         {
             await SaveSettingsAsync().ConfigureAwait(false);
             await SaveSettingsAsync().ConfigureAwait(false);
@@ -130,7 +133,8 @@ public static class Win32Window
 
 
         await WindowResizing.SetSizeAsync(vm);
         await WindowResizing.SetSizeAsync(vm);
 
 
-        IsChangingWindowState = false;
+        Dispatcher.UIThread.Post(() => IsChangingWindowState = false, DispatcherPriority.Background);
+
 
 
         if (saveSettings)
         if (saveSettings)
         {
         {