mirror of
https://github.com/QL-Win/QuickLook.git
synced 2025-09-14 20:29:07 +00:00
Fix PDF thumbnail rendering crash #1531
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Media.Imaging;
|
||||
|
||||
@@ -30,7 +31,7 @@ internal class AsyncPageToThumbnailConverter : IMultiValueConverter
|
||||
|
||||
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (values.Length < 2)
|
||||
if (values.Length < 3)
|
||||
throw new Exception("PageIdToImageConverter");
|
||||
|
||||
if (values[0] is not PdfDocumentWrapper handle) return null;
|
||||
@@ -38,11 +39,17 @@ internal class AsyncPageToThumbnailConverter : IMultiValueConverter
|
||||
var pageId = (int)values[1];
|
||||
if (pageId < 0) return null;
|
||||
|
||||
if (values[2] is not UserControl thisPdfViewer) return null;
|
||||
|
||||
var task = Task.Run(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
return handle.RenderThumbnail(pageId);
|
||||
if (handle is null || thisPdfViewer is null) return Loading;
|
||||
return thisPdfViewer.Dispatcher.Invoke(() =>
|
||||
{
|
||||
return handle.RenderThumbnail(pageId);
|
||||
});
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
@@ -62,6 +62,7 @@
|
||||
<MultiBinding Converter="{StaticResource AsyncPageToThumbnailConverter}">
|
||||
<Binding ElementName="thisPdfViewer" Path="PdfDocumentWrapper" />
|
||||
<Binding />
|
||||
<Binding ElementName="thisPdfViewer" />
|
||||
</MultiBinding>
|
||||
</Image.DataContext>
|
||||
</Image>
|
||||
|
Reference in New Issue
Block a user