Browse Source

ComPDFKit.Demo(win) - 处理PDFViewer关闭多页签时CPDFDocument没释放的问题

TangJinZhou 8 months ago
parent
commit
e1157481b1
2 changed files with 19 additions and 18 deletions
  1. 14 2
      Demo/Examples/PDFViewer/MainPage.xaml.cs
  2. 5 16
      Demo/Examples/PDFViewer/MainWindow.xaml.cs

+ 14 - 2
Demo/Examples/PDFViewer/MainPage.xaml.cs

@@ -14,14 +14,12 @@ using Microsoft.Win32;
 using System;
 using System.Collections.Generic;
 using System.ComponentModel;
-using System.IO;
 using System.Runtime.CompilerServices;
 using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Controls.Primitives;
 using System.Windows.Input;
 using ComPDFKit.Controls.PDFControlUI;
-using static ComPDFKit.Tool.CPDFToolManager;
 
 namespace PDFViewer
 {
@@ -954,6 +952,20 @@ namespace PDFViewer
                 }
             }
         }
+
+        public void CloseFile()
+        {
+            if (viewControl != null && viewControl.PDFViewTool != null)
+            {
+                CPDFViewer pdfviewer = viewControl.PDFViewTool.GetCPDFViewer();
+                CPDFDocument pdfDoc = pdfviewer?.GetDocument();
+                if(pdfDoc !=null)
+                {
+                    pdfDoc.Release();
+                }    
+            }
+        }
+
         #endregion
 
         #region Command Binding

+ 5 - 16
Demo/Examples/PDFViewer/MainWindow.xaml.cs

@@ -1,21 +1,10 @@
-using ComPDFKit.Controls.PDFControl;
-
-using System;
-using System.Collections.Generic;
+using System;
 using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 using System.Windows;
 using System.Windows.Controls;
-using System.Windows.Data;
-using System.Windows.Documents;
-using System.Windows.Input;
 using System.Windows.Media;
-using System.Windows.Media.Imaging;
-using System.Windows.Navigation;
 using System.IO;
 using System.ComponentModel;
-using System.Resources;
 using System.Runtime.CompilerServices;
 using Dragablz;
 using ComPDFKit.Controls.Helper;
@@ -24,8 +13,7 @@ using ComPDFKit.PDFDocument;
 using ComPDFKit.Controls.Data;
 using ComPDFKit.Controls.Common;
 using System.Reflection;
-using ComPDFKit.NativeMethod;
-using System.Threading;
+using ComPDFKit.Controls.PDFControl;
 
 namespace PDFViewer
 {
@@ -37,6 +25,8 @@ namespace PDFViewer
         #region Property
         private PDFViewControl passwordViewer;
         private string[] oldAndNewFilePath;
+        public event PropertyChangedEventHandler PropertyChanged;
+
         public string AppInfo
         {
             get { return Assembly.GetExecutingAssembly().GetName().Name + " " + string.Join(".", Assembly.GetExecutingAssembly().GetName().Version.ToString().Split('.').Take(3)); }
@@ -614,7 +604,6 @@ namespace PDFViewer
             this.Close();
         }
 
-
         private void HomePageButton_Toggled(object sender, RoutedEventArgs e)
         {
             if (sender is HomePageButton homePageButton && homePageButton.IsToggled)
@@ -627,11 +616,11 @@ namespace PDFViewer
             }
         }
 
-        public event PropertyChangedEventHandler PropertyChanged;
         protected virtual void OnPropertyChanged(string propertyName = null)
         {
             PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
         }
+
         protected bool UpdateProper<T>(ref T properValue, T newValue, [CallerMemberName] string properName = "")
         {
             if (object.Equals(properValue, newValue))