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;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Controls;
|
||||||
using System.Windows.Data;
|
using System.Windows.Data;
|
||||||
using System.Windows.Media.Imaging;
|
using System.Windows.Media.Imaging;
|
||||||
|
|
||||||
@@ -30,7 +31,7 @@ internal class AsyncPageToThumbnailConverter : IMultiValueConverter
|
|||||||
|
|
||||||
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
|
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
|
||||||
{
|
{
|
||||||
if (values.Length < 2)
|
if (values.Length < 3)
|
||||||
throw new Exception("PageIdToImageConverter");
|
throw new Exception("PageIdToImageConverter");
|
||||||
|
|
||||||
if (values[0] is not PdfDocumentWrapper handle) return null;
|
if (values[0] is not PdfDocumentWrapper handle) return null;
|
||||||
@@ -38,11 +39,17 @@ internal class AsyncPageToThumbnailConverter : IMultiValueConverter
|
|||||||
var pageId = (int)values[1];
|
var pageId = (int)values[1];
|
||||||
if (pageId < 0) return null;
|
if (pageId < 0) return null;
|
||||||
|
|
||||||
|
if (values[2] is not UserControl thisPdfViewer) return null;
|
||||||
|
|
||||||
var task = Task.Run(() =>
|
var task = Task.Run(() =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return handle.RenderThumbnail(pageId);
|
if (handle is null || thisPdfViewer is null) return Loading;
|
||||||
|
return thisPdfViewer.Dispatcher.Invoke(() =>
|
||||||
|
{
|
||||||
|
return handle.RenderThumbnail(pageId);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
|
@@ -62,6 +62,7 @@
|
|||||||
<MultiBinding Converter="{StaticResource AsyncPageToThumbnailConverter}">
|
<MultiBinding Converter="{StaticResource AsyncPageToThumbnailConverter}">
|
||||||
<Binding ElementName="thisPdfViewer" Path="PdfDocumentWrapper" />
|
<Binding ElementName="thisPdfViewer" Path="PdfDocumentWrapper" />
|
||||||
<Binding />
|
<Binding />
|
||||||
|
<Binding ElementName="thisPdfViewer" />
|
||||||
</MultiBinding>
|
</MultiBinding>
|
||||||
</Image.DataContext>
|
</Image.DataContext>
|
||||||
</Image>
|
</Image>
|
||||||
|
Reference in New Issue
Block a user