xaml-csharp-development-skill-for-avalonia

Platform Bootstrapping and Options

Cross-Platform Baseline

Typical shared startup:

public static AppBuilder BuildAvaloniaApp()
    => AppBuilder.Configure<App>()
        .UsePlatformDetect();

UsePlatformDetect() on desktop wires:

Skia tuning option exposed by runtime configuration:

Common Cross-Platform Extensions

Related extension host types:

Platform Extension Types

Public extension classes you will see in app startup code:

These contain entry points like UseWin32(), UseX11(), UseAvaloniaNative(), UseBrowser(), UseAndroid(), and UseiOS().

Windows (UseWin32)

Entry point:

Options:

Related enums:

Guidance:

Linux/X11 (UseX11)

Entry points:

Options:

Guidance:

macOS Native (UseAvaloniaNative)

Entry point:

Options:

Related enum:

Additional macOS options:

Browser/WebAssembly

Entry points:

Options (BrowserPlatformOptions):

Related enum:

Guidance:

Android

Entry point:

Options:

Related enum:

Guidance:

iOS

Entry points:

Options:

Related enum:

Guidance:

Linux Framebuffer and Headless

Framebuffer entry points:

Framebuffer options:

Headless entry point:

Headless options:

Use headless for tests, CI rendering checks, and non-windowed automation.

Platform Option Injection Pattern

public static AppBuilder BuildAvaloniaApp()
    => AppBuilder.Configure<App>()
        .UsePlatformDetect()
        .With(new Win32PlatformOptions
        {
            RenderingMode = new[]
            {
                Win32RenderingMode.AngleEgl,
                Win32RenderingMode.Software
            }
        })
        .With(new X11PlatformOptions
        {
            RenderingMode = new[]
            {
                X11RenderingMode.Glx,
                X11RenderingMode.Software
            }
        });

Platform Boot Mistakes

  1. Selecting only GPU path with no fallback.
  2. Scattering platform config across unrelated files.
  3. Mixing incompatible backend options in one startup profile.
  4. Tuning options without measuring startup latency and frame-time impact.
  5. Applying advanced platform-only knobs (GlProfiles, GraphicsAdapterSelectionCallback) without reproducer-backed need.

XAML-First and Code-Only Usage

Default mode:

XAML-first references:

XAML-first usage example:

<Application xmlns="https://github.com/avaloniaui"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             x:Class="MyApp.App">
  <Application.Styles>
    <FluentTheme />
    <StyleInclude Source="avares://MyApp/Styles/Common.axaml" />
  </Application.Styles>
</Application>

Code-only alternative (on request):

public static AppBuilder BuildAvaloniaApp()
    => AppBuilder.Configure<App>()
        .UsePlatformDetect()
        .With(new Win32PlatformOptions
        {
            RenderingMode = new[]
            {
                Win32RenderingMode.AngleEgl,
                Win32RenderingMode.Software
            }
        });