Refactor application to remove Windows Forms dependencies and transition to Avalonia UI
- Deleted MainWindow.xaml.cs, which contained the WPF implementation of the main window. - Updated Program.cs to remove Windows Forms initialization and support only Avalonia UI. - Removed Windows Forms specific code from ViewModelBase, including control marshalling logic.
This commit is contained in:
parent
988a3d94e1
commit
d6b778a648
16 changed files with 64 additions and 4415 deletions
|
|
@ -11,7 +11,6 @@ using Microsoft.Extensions.Logging.Console;
|
|||
using System.IO;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls.ApplicationLifetimes;
|
||||
|
||||
namespace ImageCatalog_2;
|
||||
|
||||
|
|
@ -115,10 +114,6 @@ static class Program
|
|||
static void Main(string[] args)
|
||||
{
|
||||
#if WINDOWS
|
||||
System.Windows.Forms.Application.SetHighDpiMode(System.Windows.Forms.HighDpiMode.SystemAware);
|
||||
System.Windows.Forms.Application.EnableVisualStyles();
|
||||
System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false);
|
||||
|
||||
AllocConsole();
|
||||
RedirectConsoleOutput();
|
||||
#endif
|
||||
|
|
@ -128,59 +123,7 @@ static class Program
|
|||
|
||||
ServiceProvider = serviceCollection.BuildServiceProvider();
|
||||
|
||||
var serviceProvider = ServiceProvider;
|
||||
|
||||
// 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 WINDOWS
|
||||
if (useWpf)
|
||||
{
|
||||
var wpfApp = new System.Windows.Application();
|
||||
try
|
||||
{
|
||||
wpfApp.Resources.MergedDictionaries.Add(new System.Windows.ResourceDictionary { Source = new Uri("pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml") });
|
||||
wpfApp.Resources.MergedDictionaries.Add(new System.Windows.ResourceDictionary { Source = new Uri("pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml") });
|
||||
wpfApp.Resources.MergedDictionaries.Add(new System.Windows.ResourceDictionary { Source = new Uri("pack://application:,,,/MahApps.Metro;component/Styles/Themes/Light.Blue.xaml") });
|
||||
|
||||
try
|
||||
{
|
||||
ControlzEx.Theming.ThemeManager.Current.ChangeTheme(wpfApp, "Light.Blue");
|
||||
}
|
||||
catch
|
||||
{
|
||||
// ignore if ThemeManager API isn't present
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// If resources fail to load, continue silently
|
||||
}
|
||||
|
||||
var wpfMain = serviceProvider.GetService(typeof(ImageCatalog_2.MainWindow)) as ImageCatalog_2.MainWindow;
|
||||
if (wpfMain is not null)
|
||||
{
|
||||
wpfApp.Run(wpfMain);
|
||||
return;
|
||||
}
|
||||
|
||||
// If WPF was requested but not available, fall through to WinForms.
|
||||
}
|
||||
|
||||
// Default / fallback to WinForms UI
|
||||
var mainForm = serviceProvider.GetRequiredService<MainForm>();
|
||||
System.Windows.Forms.Application.Run(mainForm);
|
||||
#else
|
||||
// On non-Windows, Avalonia is the only available UI
|
||||
BuildAvaloniaApp().StartWithClassicDesktopLifetime(args ?? Array.Empty<string>());
|
||||
#endif
|
||||
}
|
||||
|
||||
private static void ConfigureServices(ServiceCollection services)
|
||||
|
|
@ -233,11 +176,6 @@ static class Program
|
|||
|
||||
services.AddTransient<AvaloniaMainWindow>();
|
||||
|
||||
#if WINDOWS
|
||||
services.AddTransient<MainForm>();
|
||||
services.AddTransient<ImageCatalog_2.MainWindow>();
|
||||
#endif
|
||||
|
||||
services.AddSingleton<MaddoShared.IVersionProvider, MaddoShared.VersionProvider>();
|
||||
|
||||
services.AddLogging(configure =>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue