Add Avalonia UI frontend alongside WinForms and WPF

Introduce Avalonia as a new cross-platform UI option, including new XAML and code-behind files for the application and main window. Update Program.cs to support a --avalonia launch argument and add corresponding launch profile. Integrate Avalonia NuGet packages and ensure DataModel supports UI-thread invocation for all frontends. All business logic and state are shared via DI, enabling consistent behavior across WinForms, WPF, and Avalonia.
This commit is contained in:
MaddoScientisto 2026-02-26 18:43:07 +01:00
commit 311b3e76f0
8 changed files with 535 additions and 9 deletions

View file

@ -9,6 +9,8 @@ using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Logging.Console;
using System.IO;
using Microsoft.Extensions.Options;
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
namespace ImageCatalog_2;
@ -56,12 +58,18 @@ static class Program
}
public static IServiceProvider ServiceProvider { get; private set; }
public static Avalonia.AppBuilder BuildAvaloniaApp()
=> Avalonia.AppBuilder.Configure<AvaloniaApp>()
.UsePlatformDetect()
.LogToTrace();
[STAThread]
static void Main(string[] args)
{
Application.SetHighDpiMode(HighDpiMode.SystemAware);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
System.Windows.Forms.Application.SetHighDpiMode(HighDpiMode.SystemAware);
System.Windows.Forms.Application.EnableVisualStyles();
System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false);
AllocConsole();
RedirectConsoleOutput();
@ -74,8 +82,15 @@ static class Program
// Resolve WPF MainWindow when available, otherwise fall back to WinForms MainForm
var serviceProvider = ServiceProvider;
// Determine UI based on command line. Default: WinForms. Use --wpf to explicitly request WPF.
// Determine UI based on command line. Default: WinForms. Use --wpf for WPF, --avalonia for Avalonia.
bool useWpf = args is not null && Array.Exists(args, a => string.Equals(a, "--wpf", StringComparison.OrdinalIgnoreCase));
bool useAvalonia = args is not null && Array.Exists(args, a => string.Equals(a, "--avalonia", StringComparison.OrdinalIgnoreCase));
if (useAvalonia)
{
BuildAvaloniaApp().StartWithClassicDesktopLifetime(args ?? Array.Empty<string>());
return;
}
if (useWpf)
{