浏览代码

Implement Center Gallery

Ruben 8 月之前
父节点
当前提交
da558e86d7

+ 25 - 0
src/PicView.Avalonia/Gallery/GalleryFunctions.cs

@@ -245,6 +245,31 @@ public static class GalleryFunctions
         }
         }
     }
     }
 
 
+    public static void CenterGallery(MainViewModel vm)
+    {
+        if (Dispatcher.UIThread.CheckAccess())
+        {
+            Center();
+        }
+        else
+        {
+            Dispatcher.UIThread.Post(Center);
+        }
+        
+        return;
+
+        void Center()
+        {
+            var mainView = UIHelper.GetMainView;
+
+            var galleryListBox = mainView.GalleryView.GalleryListBox;
+            if (galleryListBox.Items[vm.SelectedGalleryItemIndex] is GalleryItem centerItem)
+            {
+                galleryListBox.ScrollToCenterOfItem(centerItem);
+            }
+        }
+    }
+
     #region Gallery toggle
     #region Gallery toggle
 
 
     public static bool IsFullGalleryOpen { get; private set; }
     public static bool IsFullGalleryOpen { get; private set; }

+ 1 - 2
src/PicView.Avalonia/UI/FunctionsHelper.cs

@@ -426,10 +426,9 @@ public static class FunctionsHelper
     
     
     public static async Task Center()
     public static async Task Center()
     {
     {
-        // TODO: scroll to center when the gallery is open
         await Dispatcher.UIThread.InvokeAsync(() =>
         await Dispatcher.UIThread.InvokeAsync(() =>
         {
         {
-            WindowFunctions.CenterWindowOnScreen();
+            UIHelper.Center(Vm);
         });
         });
     }
     }
 
 

+ 16 - 0
src/PicView.Avalonia/UI/UIHelper.cs

@@ -200,6 +200,22 @@ public static class UIHelper
         }
         }
     }
     }
 
 
+    public static void Center(MainViewModel? vm)
+    {
+        if (vm is null)
+        {
+            return;
+        }
+        if (GalleryFunctions.IsFullGalleryOpen)
+        {
+            GalleryFunctions.CenterGallery(vm);
+        }
+        else
+        {
+             WindowFunctions.CenterWindowOnScreen();
+        }
+    }
+
 
 
 
 
     #endregion Navigation
     #endregion Navigation