Fix issue when showing previewer multiple times.

Previously when calling ShowPreviewer  in the same process multiple times lead to an Exception inside Avalonia.
This commit is contained in:
Bebo-Maker
2022-03-23 08:35:28 +01:00
parent ff95fe287a
commit 040c47e017
@@ -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<string>());
return;
}
AppBuilder
.Configure(() => new PreviewerApp()
{