Skip to content

Application

Tom Laird-McConnell edited this page Jan 23, 2025 · 8 revisions

A Consolonia app is just an normal Avalonia app which is targeting the console platform.

To do that you

  • Bind a view to ISingleViewApplicationLifetime.MainView
  • Define the style and resources for your app

Defining the application

Define an application xaml file

<Application xmlns="https://github.com/avaloniaui"
             xmlns:console="https://github.com/jinek/consolonia"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             x:Class="ConsoloniaAppTemplate.App"
             RequestedThemeVariant="Default">
    <Application.Styles>
        <console:MaterialTheme />
    </Application.Styles>
    <Application.Resources>
    </Application.Resources>
</Application>

And a backing C# file for it which creates the MainWindow/MainView as appropriate:

public partial class App : Application
{
    public override void Initialize()
    {
        AvaloniaXamlLoader.Load(this);
    }

    public override void OnFrameworkInitializationCompleted()
    {
        if (ApplicationLifetime is ISingleViewApplicationLifetime singleLifetime)
            singleLifetime.MainView = new MainView();

        base.OnFrameworkInitializationCompleted();
    }
}
Clone this wiki locally