Skip to main content
Version: 11.0.0-rc1.1

The Main Window

The main window is the window passed to ApplicationLifetime.MainWindow in the OnFrameworkInitializationCompleted method of your your App.axaml.cs file:

public override void OnFrameworkInitializationCompleted()
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktopLifetime)
{
desktopLifetime.MainWindow = new MainWindow();
}
}

It can be retrieved at any time by casting Application.ApplicationLifetime IClassicDesktopStyleApplicationLifetime.

danger

Mobile and browser platforms don't have a concept of Window in Avalonia. Instead you need to set MainView control in Application.ApplicationLifetime when it implements ISingleViewApplicationLifetime interface.