OnPlatform Markup ExtensionOnFormFactor Markup ExtensionOn Option NodesPrimary APIs:
OnPlatformExtensionOnPlatformExtension<TReturn>OnPlatformExtensionBase<TReturn, TOn>OnFormFactorExtensionOnFormFactorExtension<TReturn>OnFormFactorExtensionBase<TReturn, TOn>On<TReturn>OnDynamicResourceExtensionKey members used in adaptive markup:
ShouldProvideOption(...)Default, Windows, macOS, Linux, Android, iOS, BrowserDesktop, Mobile, TVOptions, ContentResourceKeyOnPlatform Markup ExtensionUse OnPlatform when a value depends on runtime platform.
Important APIs:
OnPlatformExtension()OnPlatformExtension(object defaultValue)OnPlatformExtension<TReturn>()OnPlatformExtension<TReturn>(TReturn defaultValue)ShouldProvideOption(string option)OnPlatformExtensionBase<TReturn, TOn> : IAddChild<TOn>Platform-specific properties:
DefaultWindowsmacOSLinuxAndroidiOSBrowserExample:
<StackPanel xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Border Padding="{OnPlatform Default=8, Windows=10, macOS=12, Linux=10, Browser=6}" />
</StackPanel>
Use Default as a safe baseline. Override only where behavior or UX genuinely differs.
OnFormFactor Markup ExtensionUse OnFormFactor when values differ between desktop, mobile, and TV.
Important APIs:
OnFormFactorExtension()OnFormFactorExtension(object defaultValue)OnFormFactorExtension<TReturn>()OnFormFactorExtension<TReturn>(TReturn defaultValue)ShouldProvideOption(IServiceProvider serviceProvider, FormFactorType option)OnFormFactorExtensionBase<TReturn, TOn> : IAddChild<TOn>Form-factor properties:
DefaultDesktopMobileTVExample:
<StackPanel xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ItemsRepeater ItemTemplate="{OnFormFactor Default={StaticResource CompactTemplate}, Desktop={StaticResource RichTemplate}, Mobile={StaticResource CompactTemplate}}" />
</StackPanel>
On Option NodesOnPlatform and OnFormFactor support child option nodes represented by On<TReturn> / On.
Key members:
OptionsContentObject-element syntax pattern:
<TextBlock xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<TextBlock.Text>
<OnPlatform x:TypeArguments="x:String" Default="General profile">
<On Options="WINDOWS, LINUX, OSX" Content="Desktop profile" />
<On Options="ANDROID, IOS" Content="Mobile profile" />
<On Options="BROWSER" Content="Web profile" />
</OnPlatform>
</TextBlock.Text>
</TextBlock>
For OnPlatform, Options commonly uses WINDOWS, OSX, LINUX, ANDROID, IOS, BROWSER.
For OnFormFactor, use form-factor option names matching FormFactorType values (Desktop, Mobile, TV).
Use child option nodes when inline property syntax becomes hard to read.
DynamicResourceExtension is the runtime-binding markup extension for resource key lookup.
Important APIs:
DynamicResourceExtension()DynamicResourceExtension(object resourceKey)ResourceKeyProvideValue(IServiceProvider serviceProvider)Example:
<Application xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="MyApp.App">
<Application.Resources>
<Color x:Key="BrandColor">#0A84FF</Color>
<SolidColorBrush x:Key="BrandBrush" Color="{DynamicResource BrandColor}" />
</Application.Resources>
</Application>
Use DynamicResource for keys expected to change at runtime (theme/variant/plugin packs).
Common pattern:
OnPlatform/OnFormFactor,DynamicResource.<TextBlock FontSize="{OnFormFactor Default=14, Desktop=15, Mobile=13}"
Foreground="{DynamicResource BrandBrush}" />
This keeps adaptation decisions separate from actual resource values.
Default) plus minimal platform/form-factor deltas.OnPlatform and OnFormFactor in many view files.ThemeDictionaries for light/dark concerns.
ShouldProvideOption(...) will match that option.OnFormFactor option keys (Desktop, Mobile, TV).DynamicResource and the resource key remains stable.