Browse Source

compdfkit(win) - 滑动渲染抽动问题,给点击缩略图和滑动换页添加了不同的逻辑

liuaoran 1 year ago
parent
commit
e3d847a540

+ 7 - 1
Demo/Examples/Compdfkit_Tools/PDFView/PDFThumbnail/PDFThumbnailControl/CPdfThumbnailControl.xaml.cs

@@ -98,7 +98,7 @@ namespace Compdfkit_Tools.PDFControl
         {
             if (e.Key == "RenderNum")
             {
-                SelectThumbItem(pdfView.CurrentIndex);
+                SelectThumbItemWithoutGoTo(pdfView.CurrentIndex);
             }
         }
 
@@ -118,6 +118,12 @@ namespace Compdfkit_Tools.PDFControl
             ThumbControl?.SelectItem(newIndex);
         }
 
+
+        public void SelectThumbItemWithoutGoTo(int newIndex)
+        {
+            ThumbControl?.SelectItemWithoutGoTo(newIndex);
+        }
+
         private void PopulateThumbnailList()
         {
             int thumbnailWidth = thumbnailSize[zoomLevel];

+ 28 - 1
Demo/Examples/Compdfkit_Tools/PDFView/PDFThumbnail/PDFThumbnailUI/CPdfThumbnailUI.xaml.cs

@@ -1,5 +1,6 @@
 using System;
 using System.Collections.Generic;
+using System.Runtime.CompilerServices;
 using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Media;
@@ -18,6 +19,8 @@ namespace Compdfkit_Tools.PDFControlUI
         /// </summary>
         public event EventHandler<ScrollChangedEventArgs> ViewChanged;
 
+        private bool lockGoToPage;
+
         /// <summary>
         /// A list of thumbnail results
         /// </summary>
@@ -32,7 +35,12 @@ namespace Compdfkit_Tools.PDFControlUI
         /// </summary>
         private void ThumbListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
         {
-            SelectionChanged?.Invoke(this, ThumbListBox.SelectedIndex);
+            if (lockGoToPage)
+            {
+                SelectionChanged?.Invoke(this, ThumbListBox.SelectedIndex);
+
+            }
+            lockGoToPage = false;
         }
 
         /// <summary>
@@ -125,8 +133,27 @@ namespace Compdfkit_Tools.PDFControlUI
                 ThumbListBox.SelectedIndex = checkIndex;
             }
         }
+
+        /// <summary>
+        /// Select an object
+        /// </summary>
+        public void SelectItemWithoutGoTo(int checkIndex)
+        {
+            if (ThumbListBox != null && thumbResultList != null && thumbResultList.Count > checkIndex && checkIndex >= 0)
+            {
+                ThumbnailItem thumbItem = thumbResultList[checkIndex];
+                if (IsItemVisible(thumbItem) == false)
+                {
+                    ThumbListBox.ScrollIntoView(thumbItem);
+                }
+                lockGoToPage = true;
+                ThumbListBox.SelectedIndex = checkIndex;
+            }
+        }
+
     }
 
+
     /// <summary>
     /// Thumbnail object
     /// </summary>