Custom print dialog and better message registrations

This commit is contained in:
Burak Kaan Köse
2025-10-21 01:27:29 +02:00
parent 4191b7314f
commit 057edb5488
27 changed files with 656 additions and 760 deletions
@@ -14,6 +14,7 @@ using Wino.Core.Domain.Enums;
using Wino.Core.Domain.Interfaces;
using Wino.Core.Domain.Models.Accounts;
using Wino.Core.Domain.Models.Common;
using Wino.Core.Domain.Models.Printing;
using Wino.Core.WinUI.Dialogs;
using Wino.Core.WinUI.Extensions;
using Wino.Dialogs;
@@ -294,4 +295,38 @@ public class DialogServiceBase : IDialogServiceBase
return dialog.Result;
}
public async Task<WebView2PrintSettingsModel> ShowPrintDialogAsync(WebView2PrintSettingsModel initialSettings = null)
{
try
{
// Create the print dialog
var dialog = initialSettings != null
? new PrintDialog(initialSettings)
: new PrintDialog();
// Set the XamlRoot for proper display
dialog.XamlRoot = GetXamlRoot();
// Get available printers asynchronously when the dialog is loaded
dialog.Loaded += async (sender, e) =>
{
await dialog.LoadAvailablePrintersAsync();
};
// Show the dialog
var result = await HandleDialogPresentationAsync(dialog);
// Return the settings if user clicked Print, otherwise null
return result == ContentDialogResult.Primary
? dialog.PrintSettings
: null;
}
catch (Exception ex)
{
// Log the exception if logging is available
Log.Error(ex, "Error showing print dialog");
return null;
}
}
}