Files
QuestPDF/QuestPDF.Previewer/PreviewerWindow.axaml.cs
T
Bebo-Maker ea2102fe4c WIP Implemented virtualization of pages.
Render pages into seperate SKPictures
2022-03-19 17:26:58 +01:00

48 lines
1.4 KiB
C#

using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using Avalonia.Threading;
using QuestPDF.Infrastructure;
namespace QuestPDF.Previewer
{
internal class PreviewerWindow : FluentWindow
{
public DocumentRenderer DocumentRenderer { get; } = new();
public static readonly StyledProperty<IDocument?> DocumentProperty =
AvaloniaProperty.Register<PreviewerWindow, IDocument?>(nameof(Document));
public IDocument? Document
{
get => GetValue(DocumentProperty);
set => SetValue(DocumentProperty, value);
}
public PreviewerWindow()
{
InitializeComponent();
this.FindControl<Button>("GeneratePdf")
.Click += (_, _) => _ = PreviewerUtils.SavePdfWithDialog(Document, this);
DocumentProperty.Changed.Subscribe(v => Task.Run(() => DocumentRenderer.UpdateDocument(v.NewValue.Value)));
HotReloadManager.UpdateApplicationRequested += (_, _) => InvalidatePreview();
}
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
private void InvalidatePreview()
{
Dispatcher.UIThread.Post(() =>
{
var document = Document;
_ = Task.Run(() => DocumentRenderer.UpdateDocument(document));
});
}
}
}