diff --git a/QuestPDF.Previewer.Examples/Program.cs b/QuestPDF.Previewer.Examples/Program.cs index fb2d971..7e218a8 100644 --- a/QuestPDF.Previewer.Examples/Program.cs +++ b/QuestPDF.Previewer.Examples/Program.cs @@ -7,9 +7,9 @@ using QuestPDF.ReportSample; using QuestPDF.ReportSample.Layouts; using Colors = QuestPDF.Helpers.Colors; -// var model = DataSource.GetReport(); -// var report = new StandardReport(model); -// report.ShowInPreviewer(); +var model = DataSource.GetReport(); +var report = new StandardReport(model); +report.ShowInPreviewer(); Document .Create(container => diff --git a/QuestPDF.Previewer/DocumentPreviewerExtensions.cs b/QuestPDF.Previewer/DocumentPreviewerExtensions.cs index 1a335ac..29f3f70 100644 --- a/QuestPDF.Previewer/DocumentPreviewerExtensions.cs +++ b/QuestPDF.Previewer/DocumentPreviewerExtensions.cs @@ -1,4 +1,5 @@ using Avalonia; +using Avalonia.Controls.ApplicationLifetimes; using QuestPDF.Infrastructure; namespace QuestPDF.Previewer @@ -17,6 +18,19 @@ namespace QuestPDF.Previewer { ArgumentNullException.ThrowIfNull(document); + //Currently there is no way to unitialize a previously run avalonia app. + //So we need to check if the previewer was already run and show the window again. + if(Application.Current?.ApplicationLifetime is ClassicDesktopStyleApplicationLifetime desktop) + { + desktop.MainWindow = new PreviewerWindow() + { + Document = document, + }; + desktop.MainWindow.Show(); + desktop.Start(Array.Empty()); + return; + } + AppBuilder .Configure(() => new PreviewerApp() { diff --git a/QuestPDF.Previewer/InteractiveCanvas.cs b/QuestPDF.Previewer/InteractiveCanvas.cs index 26a6789..2c808ac 100644 --- a/QuestPDF.Previewer/InteractiveCanvas.cs +++ b/QuestPDF.Previewer/InteractiveCanvas.cs @@ -27,7 +27,8 @@ class InteractiveCanvas : ICustomDrawOperation public float TotalPagesHeight => Pages.Sum(x => x.Size.Height) + (Pages.Count - 1) * PageSpacing; public float TotalHeight => TotalPagesHeight + SafeZone * 2 / Scale; - public float MaxWidth => Pages.Max(x => x.Size.Width); + public float MaxWidth => Pages.Any() ? Pages.Max(x => x.Size.Width) : 0; + public float MaxTranslateY => -(Height / 2 - SafeZone) / Scale; public float MinTranslateY => (Height / 2 + SafeZone) / Scale - TotalHeight; diff --git a/QuestPDF.Previewer/PreviewerWindow.axaml.cs b/QuestPDF.Previewer/PreviewerWindow.axaml.cs index d2524a4..0813933 100644 --- a/QuestPDF.Previewer/PreviewerWindow.axaml.cs +++ b/QuestPDF.Previewer/PreviewerWindow.axaml.cs @@ -23,55 +23,55 @@ namespace QuestPDF.Previewer get => GetValue(DocumentProperty); set => SetValue(DocumentProperty, value); } - - - + public static readonly StyledProperty CurrentScrollProperty = AvaloniaProperty.Register(nameof(CurrentScroll)); - + public float CurrentScroll { get => GetValue(CurrentScrollProperty); set => SetValue(CurrentScrollProperty, value); } - + public static readonly StyledProperty ScrollViewportSizeProperty = AvaloniaProperty.Register(nameof(ScrollViewportSize)); - + public float ScrollViewportSize { get => GetValue(ScrollViewportSizeProperty); set => SetValue(ScrollViewportSizeProperty, value); } - + public static readonly StyledProperty VerticalScrollbarVisibleProperty = AvaloniaProperty.Register(nameof(VerticalScrollbarVisible)); - + public bool VerticalScrollbarVisible { get => GetValue(VerticalScrollbarVisibleProperty); set => SetValue(VerticalScrollbarVisibleProperty, value); } - - + public PreviewerWindow() { InitializeComponent(); - ScrollViewportSizeProperty.Changed.Subscribe(_ => - { - VerticalScrollbarVisible = ScrollViewportSize < 1; - }); - + ScrollViewportSizeProperty.Changed + .Subscribe(e => Dispatcher.UIThread.Post(() => + { + VerticalScrollbarVisible = e.NewValue.Value < 1; + })); + // this.FindControl