Fix PDF thumbnail rendering crash #1531

This commit is contained in:
ema
2025-07-01 04:30:08 +08:00
parent 72c8e567cd
commit 1f13aa6678
2 changed files with 10 additions and 2 deletions

View File

@@ -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
{
if (handle is null || thisPdfViewer is null) return Loading;
return thisPdfViewer.Dispatcher.Invoke(() =>
{
return handle.RenderThumbnail(pageId);
});
}
catch (Exception)
{

View File

@@ -62,6 +62,7 @@
<MultiBinding Converter="{StaticResource AsyncPageToThumbnailConverter}">
<Binding ElementName="thisPdfViewer" Path="PdfDocumentWrapper" />
<Binding />
<Binding ElementName="thisPdfViewer" />
</MultiBinding>
</Image.DataContext>
</Image>