Skip to content

Commit ff2afb1

Browse files
committed
Added unload feature to unload current pdfs
1 parent 873eb7a commit ff2afb1

File tree

6 files changed

+52
-7
lines changed

6 files changed

+52
-7
lines changed

Diff for: src/MoonPdf/Properties/AssemblyInfo.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,5 @@ You should have received a copy of the GNU General Public License
6464
// You can specify all the values or you can default the Build and Revision Numbers
6565
// by using the '*' as shown below:
6666
// [assembly: AssemblyVersion("1.0.*")]
67-
[assembly: AssemblyVersion("0.3.0.0")]
68-
[assembly: AssemblyFileVersion("0.3.0.0")]
67+
[assembly: AssemblyVersion("0.3.1.0")]
68+
[assembly: AssemblyFileVersion("0.3.1.0")]

Diff for: src/MoonPdfLib/ContinuousMoonPdfPanel.xaml.cs

+20-1
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,28 @@ public void Load(IPdfSource source, string password = null)
7575
this.ZoomToWidth();
7676

7777
if (this.scrollViewer != null)
78+
{
79+
this.scrollViewer.Visibility = System.Windows.Visibility.Visible;
7880
this.scrollViewer.ScrollToTop();
81+
}
7982
}
80-
83+
84+
public void Unload()
85+
{
86+
this.scrollViewer.Visibility = System.Windows.Visibility.Collapsed;
87+
this.scrollViewer.ScrollToHorizontalOffset(0);
88+
this.scrollViewer.ScrollToVerticalOffset(0);
89+
this.imageProvider = null;
90+
91+
if (this.virtualizingPdfPages != null)
92+
{
93+
this.virtualizingPdfPages.CleanUpAllPages();
94+
this.virtualizingPdfPages = null;
95+
}
96+
97+
this.itemsControl.ItemsSource = null;
98+
}
99+
81100
private void CreateNewItemsSource()
82101
{
83102
var pageTimeout = TimeSpan.FromSeconds(2);

Diff for: src/MoonPdfLib/IMoonPdfPanel.cs

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ internal interface IMoonPdfPanel
3333
UserControl Instance { get; }
3434
float CurrentZoom { get; }
3535
void Load(IPdfSource source, string password = null);
36+
void Unload();
3637
void Zoom(double zoomFactor);
3738
void ZoomIn();
3839
void ZoomOut();

Diff for: src/MoonPdfLib/MoonPdfPanel.xaml.cs

+13-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,19 @@ public void Open(IPdfSource source, string password = null)
211211
if (this.PdfLoaded != null)
212212
this.PdfLoaded(this, EventArgs.Empty);
213213
}
214-
214+
215+
public void Unload()
216+
{
217+
this.CurrentSource = null;
218+
this.CurrentPassword = null;
219+
this.TotalPages = 0;
220+
221+
this.innerPanel.Unload();
222+
223+
if (this.PdfLoaded != null)
224+
this.PdfLoaded(this, EventArgs.Empty);
225+
}
226+
215227
private void LoadPdf(IPdfSource source, string password)
216228
{
217229
var pageBounds = MuPdfWrapper.GetPageBounds(source, this.Rotation, password);

Diff for: src/MoonPdfLib/Properties/AssemblyInfo.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,5 @@ You should have received a copy of the GNU General Public License
4545
// You can specify all the values or you can default the Build and Revision Numbers
4646
// by using the '*' as shown below:
4747
// [assembly: AssemblyVersion("1.0.*")]
48-
[assembly: AssemblyVersion("0.3.0.0")]
49-
[assembly: AssemblyFileVersion("0.3.0.0")]
48+
[assembly: AssemblyVersion("0.3.1.0")]
49+
[assembly: AssemblyFileVersion("0.3.1.0")]

Diff for: src/MoonPdfLib/SinglePageMoonPdfPanel.xaml.cs

+14-1
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,27 @@ public void Load(IPdfSource source, string password = null)
5959

6060
currentPageIndex = 0;
6161

62+
if (this.scrollViewer != null)
63+
this.scrollViewer.Visibility = System.Windows.Visibility.Visible;
64+
6265
if (this.parent.ZoomType == ZoomType.Fixed)
6366
this.SetItemsSource();
6467
else if (this.parent.ZoomType == ZoomType.FitToHeight)
6568
this.ZoomToHeight();
6669
else if (this.parent.ZoomType == ZoomType.FitToWidth)
6770
this.ZoomToWidth();
6871
}
69-
72+
73+
public void Unload()
74+
{
75+
this.scrollViewer.Visibility = System.Windows.Visibility.Collapsed;
76+
this.scrollViewer.ScrollToHorizontalOffset(0);
77+
this.scrollViewer.ScrollToVerticalOffset(0);
78+
currentPageIndex = 0;
79+
80+
this.imageProvider = null;
81+
}
82+
7083
ScrollViewer IMoonPdfPanel.ScrollViewer
7184
{
7285
get { return this.scrollViewer; }

0 commit comments

Comments
 (0)