use Dispatcher instead of Loaded event

This commit is contained in:
Paddy Xu
2017-05-27 00:38:29 +03:00
parent 4c82f1a9f4
commit 250e796095

View File

@@ -1,5 +1,6 @@
using System; using System;
using System.IO; using System.IO;
using System.Windows.Threading;
namespace QuickLook.Plugin.PDFViewer namespace QuickLook.Plugin.PDFViewer
{ {
@@ -37,16 +38,27 @@ namespace QuickLook.Plugin.PDFViewer
_pdfControl = new PdfViewerControl(); _pdfControl = new PdfViewerControl();
context.ViewerContent = _pdfControl; context.ViewerContent = _pdfControl;
_pdfControl.Loaded += (sender, e) => Exception exception = null;
_pdfControl.Dispatcher.BeginInvoke(new Action(() =>
{ {
_pdfControl.LoadPdf(path); try
{
_pdfControl.LoadPdf(path);
context.Title = $"{Path.GetFileName(path)} (1 / {_pdfControl.TotalPages})"; context.Title = $"{Path.GetFileName(path)} (1 / {_pdfControl.TotalPages})";
_pdfControl.CurrentPageChanged += (sender2, e2) => context.Title = _pdfControl.CurrentPageChanged += (sender2, e2) => context.Title =
$"{Path.GetFileName(path)} ({_pdfControl.CurrentPage + 1} / {_pdfControl.TotalPages})"; $"{Path.GetFileName(path)} ({_pdfControl.CurrentPage + 1} / {_pdfControl.TotalPages})";
context.IsBusy = false;
}
catch (Exception e)
{
exception = e;
}
}), DispatcherPriority.Loaded).Wait();
context.IsBusy = false; if (exception != null)
}; throw exception;
} }
public void Cleanup() public void Cleanup()