Support UI selection via --wpf command-line argument
Refactored Program.cs to accept command-line arguments and select between WinForms (default) and WPF UI based on the presence of --wpf. Removed old commented-out UI selection code. Updated launchSettings.json to provide separate profiles for WinForms and WPF launches. If WPF is requested but unavailable, the app falls back to WinForms.
This commit is contained in:
parent
67f207c05b
commit
d068b4b3e1
2 changed files with 27 additions and 26 deletions
|
|
@ -57,7 +57,7 @@ static class Program
|
||||||
|
|
||||||
public static IServiceProvider ServiceProvider { get; private set; }
|
public static IServiceProvider ServiceProvider { get; private set; }
|
||||||
[STAThread]
|
[STAThread]
|
||||||
static void Main()
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
Application.SetHighDpiMode(HighDpiMode.SystemAware);
|
Application.SetHighDpiMode(HighDpiMode.SystemAware);
|
||||||
Application.EnableVisualStyles();
|
Application.EnableVisualStyles();
|
||||||
|
|
@ -74,18 +74,11 @@ static class Program
|
||||||
// Resolve WPF MainWindow when available, otherwise fall back to WinForms MainForm
|
// Resolve WPF MainWindow when available, otherwise fall back to WinForms MainForm
|
||||||
var serviceProvider = ServiceProvider;
|
var serviceProvider = ServiceProvider;
|
||||||
|
|
||||||
// NOTE: By default the app will attempt to run the WPF window when available and fall back
|
// Determine UI based on command line. Default: WinForms. Use --wpf to explicitly request WPF.
|
||||||
// to the WinForms MainForm. If you want to force the WinForms UI for testing, uncomment
|
bool useWpf = args is not null && Array.Exists(args, a => string.Equals(a, "--wpf", StringComparison.OrdinalIgnoreCase));
|
||||||
// the block below and comment out the WPF branch.
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
// // Force WinForms UI (uncomment to enable)
|
|
||||||
//var mainForm = serviceProvider.GetRequiredService<MainForm>();
|
|
||||||
//// If you want to set the DataModel explicitly on the WinForms form use the lines below
|
|
||||||
//// var mainViewModel = serviceProvider.GetRequiredService<DataModel>();
|
|
||||||
//// mainForm.Model = mainViewModel;
|
|
||||||
//Application.Run(mainForm);
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
if (useWpf)
|
||||||
|
{
|
||||||
// Create the WPF Application and merge MahApps resources BEFORE constructing the MainWindow
|
// Create the WPF Application and merge MahApps resources BEFORE constructing the MainWindow
|
||||||
// so InitializeComponent sees the theme resources on first render.
|
// so InitializeComponent sees the theme resources on first render.
|
||||||
var wpfApp = new System.Windows.Application();
|
var wpfApp = new System.Windows.Application();
|
||||||
|
|
@ -119,7 +112,10 @@ static class Program
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fallback to WinForms UI
|
// If WPF was requested but not available, fall back to WinForms.
|
||||||
|
}
|
||||||
|
|
||||||
|
// Default / fallback to WinForms UI
|
||||||
var mainForm = serviceProvider.GetRequiredService<MainForm>();
|
var mainForm = serviceProvider.GetRequiredService<MainForm>();
|
||||||
System.Windows.Forms.Application.Run(mainForm);
|
System.Windows.Forms.Application.Run(mainForm);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,12 @@
|
||||||
{
|
{
|
||||||
"profiles": {
|
"profiles": {
|
||||||
"Profile 1": {
|
"ImageCatalog (WinForms)": {
|
||||||
"commandName": "Project"
|
"commandName": "Project",
|
||||||
|
"commandLineArgs": ""
|
||||||
|
},
|
||||||
|
"ImageCatalog (WPF)": {
|
||||||
|
"commandName": "Project",
|
||||||
|
"commandLineArgs": "--wpf"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue