Use this reference to make reusable component families instead of one-off styles.
Primary APIs:
ControlTheme, StyledElement.ThemeStyle, nested selectors, TemplateBindingItemsControl.ItemContainerThemeFlyout.FlyoutPresenterTheme, MenuFlyout.ItemContainerThemeHigh-value theme members:
StyledElement.ThemePropertyStyledElement.ThemeItemsControl.ItemContainerThemePropertyItemsControl.ItemContainerThemeFlyout.FlyoutPresenterThemePropertyFlyout.FlyoutPresenterThemeMenuFlyout.ItemContainerThemePropertyMenuFlyout.FlyoutPresenterThemePropertyTemplateBinding<ResourceDictionary xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ControlTheme x:Key="PrimaryButtonTheme"
TargetType="Button"
BasedOn="{StaticResource {x:Type Button}}">
<Setter Property="Padding" Value="{DynamicResource Inset.Control}" />
<Setter Property="CornerRadius" Value="{DynamicResource Radius.100}" />
<Setter Property="Background" Value="{DynamicResource Brush.Action.Primary}" />
<Setter Property="Foreground" Value="White" />
<Setter Property="BorderBrush" Value="{DynamicResource Brush.Action.Primary}" />
<Style Selector="^:pointerover">
<Setter Property="Background" Value="{DynamicResource Brush.Action.Primary.Hover}" />
</Style>
</ControlTheme>
<ControlTheme x:Key="CardSurfaceTheme"
TargetType="Border">
<Setter Property="Background" Value="{DynamicResource Brush.Surface.Card}" />
<Setter Property="BorderBrush" Value="{DynamicResource Brush.Border.Subtle}" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="CornerRadius" Value="{DynamicResource Radius.200}" />
<Setter Property="Padding" Value="{DynamicResource Inset.Card}" />
</ControlTheme>
</ResourceDictionary>
<ResourceDictionary xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ControlTheme x:Key="NavItemTheme"
TargetType="ListBoxItem"
BasedOn="{StaticResource {x:Type ListBoxItem}}">
<Setter Property="Padding" Value="12,10" />
<Setter Property="Margin" Value="0,0,0,4" />
<Setter Property="CornerRadius" Value="{DynamicResource Radius.100}" />
</ControlTheme>
<ControlTheme x:Key="OverlayPresenterTheme"
TargetType="FlyoutPresenter"
BasedOn="{StaticResource {x:Type FlyoutPresenter}}">
<Setter Property="Background" Value="{DynamicResource Brush.Surface.Card}" />
<Setter Property="BorderBrush" Value="{DynamicResource Brush.Border.Subtle}" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="CornerRadius" Value="{DynamicResource Radius.200}" />
<Setter Property="Padding" Value="6" />
</ControlTheme>
</ResourceDictionary>
<ListBox ItemContainerTheme="{StaticResource NavItemTheme}" />
<MenuFlyout FlyoutPresenterTheme="{StaticResource OverlayPresenterTheme}" />
ControlTheme resources over runtime template creation.Do:
BasedOn to preserve control defaults,Do not:
ControlTheme or semantic resources.ItemContainerTheme explicitly instead of styling only the content template.