Primary WPF APIs:
PrintDialogDocumentPaginatorFlowDocument/FixedDocument print flowsPrimary Avalonia patterns:
| WPF | Avalonia |
|---|---|
PrintDialog.PrintDocument(...) |
explicit export service + preview/launch flow |
DocumentPaginator print paging |
report pagination in app services/view-models |
| sync print flow | async export and user-driven open/print steps |
Avalonia core does not provide direct equivalents for WPF printing APIs.
WPF C#:
var dialog = new PrintDialog();
if (dialog.ShowDialog() == true)
dialog.PrintDocument(((IDocumentPaginatorSource)document).DocumentPaginator, "Report");
Avalonia XAML:
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="using:MyApp.ViewModels"
x:DataType="vm:ReportViewModel">
<StackPanel Spacing="8">
<Button Content="Preview Report"
Command="{CompiledBinding PreviewReportCommand}" />
<Button Content="Export Report"
Command="{CompiledBinding ExportReportCommand}" />
</StackPanel>
</UserControl>
using System.IO;
using System.Threading.Tasks;
using Avalonia.Controls;
using Avalonia.Platform.Storage;
public static async Task ExportReportAsync(TopLevel topLevel, string reportText)
{
var file = await topLevel.StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions
{
Title = "Export Report",
SuggestedFileName = "report.txt",
FileTypeChoices = new[]
{
new FilePickerFileType("Text") { Patterns = new[] { "*.txt" } }
}
});
if (file is null)
return;
await using var stream = await file.OpenWriteAsync();
await using var writer = new StreamWriter(stream);
await writer.WriteAsync(reportText);
await topLevel.Launcher.LaunchFileAsync(file);
}