Browse Source

avalonia: Added Page Counter to document viewer for PDFs

Kenric Nugteren 1 week ago
parent
commit
ebe215c0cb

+ 1 - 1
PRS.Avalonia/PRS.Avalonia/Components/DocumentList/DocumentViewer.axaml

@@ -16,7 +16,7 @@
                HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                HorizontalContentAlignment="Center" VerticalContentAlignment="Center"
                Foreground="Gray"/>
-        <Label Grid.Row="1" Grid.Column="1"
+        <Label Name="FileNameLabel" Grid.Row="1" Grid.Column="1"
                Content="{Binding $parent[components:DocumentViewer].FileName}"
                HorizontalContentAlignment="Center"/>
         <Button Classes="Standard"

+ 12 - 5
PRS.Avalonia/PRS.Avalonia/Components/DocumentList/DocumentViewer.axaml.cs

@@ -82,10 +82,7 @@ public partial class DocumentViewer : UserControl
 
         public async Task<byte[]?> GetPage()
         {
-            if(RenderedPage is null)
-            {
-                RenderedPage = await PlatformTools.PdfRenderer.PdfToImageAsync(PdfData, Page, 300);
-            }
+            RenderedPage ??= await PlatformTools.PdfRenderer.PdfToImageAsync(PdfData, Page, 300);
             return RenderedPage;
         }
     }
@@ -108,8 +105,16 @@ public partial class DocumentViewer : UserControl
             RightButton.IsVisible = _pages.Length > 1;
             LeftButton.IsEnabled = _page > 0;
             RightButton.IsEnabled = _page < _pages.Length - 1;
+            if(_pages.Length > 1)
+            {
+                FileNameLabel.Content = $"{FileName} (Page {_page + 1}/{_pages.Length})";
+            }
+            else
+            {
+                FileNameLabel.Content = FileName;
+            }
 
-            var imageSource = ByteArrayToImageSourceConverter.Instance.Convert(await _pages[_page].GetPage());
+                var imageSource = ByteArrayToImageSourceConverter.Instance.Convert(await _pages[_page].GetPage());
             if(imageSource is not null)
             {
                 Image.Source = imageSource;
@@ -126,6 +131,7 @@ public partial class DocumentViewer : UserControl
         {
             LeftButton.IsVisible = false;
             RightButton.IsVisible = false;
+            FileNameLabel.Content = FileName;
 
             NoImage.IsVisible = true;
             Zoom.IsVisible = false;
@@ -150,6 +156,7 @@ public partial class DocumentViewer : UserControl
         }
         else
         {
+            FileNameLabel.Content = FileName;
             NoImage.IsVisible = true;
             Zoom.IsVisible = false;
         }