How to write the Windows Initialization in pure C#?

javierv 1 Reputation point
2022-06-21T15:11:42.353+00:00

The bootstrap code for the Windows platform uses App.xaml.cs and App.xaml

App.xaml

   <maui:MauiWinUIApplication  
       x:Class="ExampleMauiApp.WinUI.App"  
       xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
       xmlns:maui="using:Microsoft.Maui"  
       xmlns:local="using:ExampleMauiApp.WinUI">  
   </maui:MauiWinUIApplication>  

and

App.xaml.cs

   using Microsoft.UI.Xaml;  
     
   // To learn more about WinUI, the WinUI project structure,  
   // and more about our project templates, see: http://aka.ms/winui-project-info.  
     
   namespace ExampleMauiApp.WinUI;  
     
   /// <summary>  
   /// Provides application-specific behavior to supplement the default Application class.  
   /// </summary>  
   public partial class App : MauiWinUIApplication  
   {  
   	/// <summary>  
   	/// Initializes the singleton application object.  This is the first line of authored code  
   	/// executed, and as such is the logical equivalent of main() or WinMain().  
   	/// </summary>  
   	public App()  
   	{  
   		this.InitializeComponent();  // (1)  
   	}  
     
   	protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();  
   }  

I want to replace the partial class and initialize the Application object programmatically without using the call to InitializeComponent that loads the XAML file.
Do you know what's required to do that? Maybe there is a builder or factory class that returns an application object so then I can programmatically setup additional
things.
I've tried to debug the code but for some reason, I can't load the debug symbols of Microsoft.UI.Xaml.Application.LoadComponent.
Just for info I've loaded all the symbols using Tools -> Options -> Debugging -> Symbols, but maybe I'm missing something.

Thanks.
--jv

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
2,854 questions
{count} votes