Theme Service
Overview
IThemeService controls the application's visual appearance: which theme is active (Dark or Light) and whether the UI uses the compact density. Assigning a theme applies the matching Avalonia ThemeVariant to Application.Current.RequestedThemeVariant and takes effect immediately; compact mode switches the Fluent theme's DensityStyle between Compact and Normal.
Both values are stored in ThemeServiceConfig (theme defaults to dark, compact to false) and restored on startup. The service exposes its state as reactive properties, so a view model can read the current value and react to changes through the same member.
Available Themes
The default ThemeService ships these two themes:
Id | Constant | Avalonia variant |
|---|---|---|
|
|
|
|
|
|
The list is hardcoded in that implementation — there is no DI hook to extend it.
Usage
Read or change the current theme through CurrentTheme.Value. Always assign one of the items from Themes — any other IThemeInfo implementation is rejected and applies nothing:
To react to changes, subscribe to the property. SynchronizedReactiveProperty<T> pushes its current value on subscribe, so use Skip(1) when you only care about subsequent changes:
Registration
The service is part of the core services and takes no configuration:
In a design-time environment the registration substitutes NullThemeService.Instance instead.
API
IThemeService
Manages the application's theme and control density.
Property | Type | Description |
|---|---|---|
|
| All available themes. |
|
| Gets the active theme selected from |
|
| Whether compact density is on. Assigning it applies the density and persists it. |
IThemeInfo
Represents a theme item.
Property | Type | Description |
|---|---|---|
|
| Unique id of the theme (e.g. |
|
| Localized display name. |
ThemeItem
Represents the default IThemeInfo implementation.
Property | Type | Description |
|---|---|---|
|
| Avalonia theme variant applied when the theme is selected. |