Use this reference to build the token backbone for a professional Avalonia app.
Primary APIs:
Application.Resources, Application.StylesResourceDictionary, MergedDictionaries, ThemeDictionariesThemeVariant, ThemeVariantScopeDynamicResourceExtension, ResourceInclude, StyleIncludeStyle, ControlTheme, StyledElement.ThemeUse three layers:
Brush.Text.Primary or Brush.Surface.Card.Button.Primary.Padding or Shell.Nav.RailWidth.Recommended structure:
Design/
Tokens/
Primitives.axaml
Semantic.LightDark.axaml
Component.Buttons.axaml
Component.Shell.axaml
<Application xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
RequestedThemeVariant="Default">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceInclude Source="avares://MyApp/Design/Tokens/Primitives.axaml" />
<ResourceInclude Source="avares://MyApp/Design/Tokens/Semantic.LightDark.axaml" />
<ResourceInclude Source="avares://MyApp/Design/Tokens/Component.Buttons.axaml" />
<ResourceInclude Source="avares://MyApp/Design/Tokens/Component.Shell.axaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
Primitive and semantic example:
<ResourceDictionary xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<x:Double x:Key="Space.100">4</x:Double>
<x:Double x:Key="Space.200">8</x:Double>
<x:Double x:Key="Space.400">16</x:Double>
<CornerRadius x:Key="Radius.100">8</CornerRadius>
<Thickness x:Key="Inset.Control">14,10</Thickness>
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Light">
<Color x:Key="Color.Surface.Card">#FFFFFFFF</Color>
<Color x:Key="Color.Text.Primary">#FF16181D</Color>
</ResourceDictionary>
<ResourceDictionary x:Key="Dark">
<Color x:Key="Color.Surface.Card">#FF171A20</Color>
<Color x:Key="Color.Text.Primary">#FFF7F9FC</Color>
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>
<SolidColorBrush x:Key="Brush.Surface.Card" Color="{DynamicResource Color.Surface.Card}" />
<SolidColorBrush x:Key="Brush.Text.Primary" Color="{DynamicResource Color.Text.Primary}" />
</ResourceDictionary>
ThemeDictionaries, not code-behind branches.ControlTheme for reusable families and plain Style for small selector-based adjustments.DynamicResource only for values expected to change.Do:
Do not:
StaticResource instead of DynamicResource.