Goal
Why this matters
Avalonia.Controls.ColorPicker or Avalonia.Controls.Notifications; knowing what ships in the box saves time.Prerequisites
Avalonia groups advanced controls into focused namespaces:
| Module | Namespace | Highlights |
|---|---|---|
| Color editing | Avalonia.Controls.ColorPicker |
ColorPicker, ColorView, palette data, HSV/RGB components |
| Refresh gestures | Avalonia.Controls.PullToRefresh |
RefreshContainer, RefreshVisualizer, RefreshInfoProvider |
| Notifications | Avalonia.Controls.Notifications |
WindowNotificationManager, NotificationCard, INotification |
| Date & time | Avalonia.Controls.DateTimePickers |
DatePicker, TimePicker, presenters, culture support |
| Interactive navigation | Avalonia.Controls.SplitView, Avalonia.Controls.SplitButton |
Collapsible panes, hybrid buttons |
| Document text | Avalonia.Controls.Documents |
Inline elements (Run, Bold, InlineUIContainer) |
| Misc UX | Avalonia.Controls.TransitioningContentControl, Avalonia.Controls.Notifications.ReversibleStackPanel, Avalonia.Controls.Primitives helpers |
Each module ships styles in Fluent/Simple theme dictionaries. Include the relevant .axaml resource dictionaries when building custom themes.
ColorPicker extends ColorView by providing a preview area and flyout editing UI (ColorPicker.cs). Key elements:
Content/ContentTemplate (defaults to swatch + ARGB string).ColorSpectrum, sliders, and palette pickers.ColorPalettes/*—you can supply custom palettes or localize names.Usage snippet:
<ColorPicker SelectedColor="{Binding AccentColor, Mode=TwoWay}">
<ColorPicker.ContentTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Spacing="8">
<Border Width="24" Height="24" Background="{Binding}" CornerRadius="4"/>
<TextBlock Text="{Binding Converter={StaticResource RgbFormatter}}"/>
</StackPanel>
</DataTemplate>
</ColorPicker.ContentTemplate>
</ColorPicker>
Tips:
ColorPicker.FlyoutPlacement (via template) to adapt for touch vs desktop usage.ColorView.ColorChanged to react immediately to slider changes (e.g., update live preview alt text).ColorPickerAutomationPeer) if you expose color selection to screen readers.RefreshContainer wraps scrollable content and coordinates RefreshVisualizer animations (RefreshContainer.cs). Concepts:
PullDirection (top/bottom/left/right) chooses gesture direction.RefreshRequested event fires when the user crosses the threshold. Use RefreshCompletionDeferral to await async work.RefreshInfoProviderAdapter adapts ScrollViewer offsets to the visualizer; you can replace it for custom panels.Example:
<ptr:RefreshContainer RefreshRequested="OnRefresh">
<ptr:RefreshContainer.Visualizer>
<ptr:RefreshVisualizer Orientation="TopToBottom"
Content="{DynamicResource PullHintTemplate}"/>
</ptr:RefreshContainer.Visualizer>
<ScrollViewer>
<ItemsControl ItemsSource="{Binding FeedItems}"/>
</ScrollViewer>
</ptr:RefreshContainer>
private async void OnRefresh(object? sender, RefreshRequestedEventArgs e)
{
using var deferral = e.GetDeferral();
await ViewModel.LoadLatestAsync();
}
Notes:
RefreshVisualizer.StateChanged (show "Release to refresh" vs "Refreshing...").ItemsControl defers updates until after refresh completes so the visualizer can retract smoothly.WindowNotificationManager hosts toast-like notifications overlaying a TopLevel (WindowNotificationManager.cs).
Position (TopRight, BottomCenter, etc.) and MaxItems.Show(INotification) or Show(object); the manager wraps content in a NotificationCard with pseudo-classes per NotificationType.WindowNotificationManager to your main window (new WindowNotificationManager(this) or via XAML NotificationLayer).Custom template example:
<Style Selector="NotificationCard">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="NotificationCard">
<Border Classes="toast" CornerRadius="6" Background="{ThemeResource SurfaceBrush}">
<StackPanel Orientation="Vertical" Margin="12">
<TextBlock Text="{Binding Content.Title}" FontWeight="SemiBold"/>
<TextBlock Text="{Binding Content.Message}" TextWrapping="Wrap"/>
<Button Content="Dismiss" Classes="subtle"
notifications:NotificationCard.CloseOnClick="True"/>
</StackPanel>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Considerations:
Esc to close the newest notification.INotificationManager in DI so view models can raise toasts without referencing the view.DatePicker and TimePicker share presenters and respect culture-specific formats (DatePicker.cs, TimePicker.cs).
SelectedDate, MinYear, MaxYear, DayVisible, MonthFormat, YearFormat.DateTimeOffset? (stay mindful of time zones).Validation strategies:
Binding with data annotations or manual rules to block invalid ranges.:hasnodate when SelectedDate is null.Calendar gives you a full month or decade view without the flyout wrapper.
DisplayMode toggles Month, Year, or Decade views—useful for date pickers embedded in dashboards.SelectedDates supports multi-selection when SelectionMode is MultipleRange; bind it to a collection for booking scenarios.DisplayDateChanged to lazy-load data (appointments, deadlines) as the user browses months.PART_DaysPanel and related names intact so the control keeps functioning.When you need both Calendar and DatePicker, reuse the same CalendarDatePicker styles so typography and spacing stay consistent.
SplitView builds side drawers with flexible display modes (SplitView.cs).
DisplayMode: Overlay, Inline, CompactOverlay, CompactInline.IsPaneOpen toggles state; handle PaneOpening/PaneClosing to intercept.UseLightDismissOverlayMode enables auto-dismiss when the user clicks outside.Usage example:
<SplitView IsPaneOpen="{Binding IsMenuOpen, Mode=TwoWay}"
DisplayMode="CompactOverlay"
PanePlacement="Left"
CompactPaneLength="56"
OpenPaneLength="240">
<SplitView.Pane>
<StackPanel>
<Button Content="Dashboard" Command="{Binding GoHome}"/>
<Button Content="Reports" Command="{Binding GoReports}"/>
</StackPanel>
</SplitView.Pane>
<Frame Content="{Binding CurrentPage}"/>
</SplitView>
Tips:
HotKey to SplitButton or global command).TransitioningContentControl (Chapter 29) for smooth page transitions.TransitioningContentControl wraps a content presenter with IPageTransition support.
PageTransition in XAML (slide, cross-fade, custom transitions) to animate view-model swaps.TransitionCompleted to dispose old view models or trigger analytics when navigation ends.SplitView or navigation shells to animate content panes independently of the chrome.For component galleries, use it to showcase before/after states or responsive layouts without writing manual animation plumbing.
SplitButton provides a main action plus a secondary flyout (SplitButton.cs).
Click/Command; the secondary button shows Flyout.:flyout-open, :pressed, :checked (for ToggleSplitButton).MenuFlyout for command lists or settings.Example:
<SplitButton Content="Export"
Command="{Binding ExportAll}">
<SplitButton.Flyout>
<MenuFlyout>
<MenuItem Header="Export CSV" Command="{Binding ExportCsv}"/>
<MenuItem Header="Export JSON" Command="{Binding ExportJson}"/>
</MenuFlyout>
</SplitButton.Flyout>
</SplitButton>
Ensure Command.CanExecute updates by binding to view model state; SplitButton listens for CanExecuteChanged and toggles IsEnabled accordingly.
Inline, Run, Span, and InlineUIContainer in Avalonia.Controls.Documents let you build rich text with embedded controls (useful for notifications or chat bubbles).InlineUIContainer sparingly; it affects layout performance.NotificationCard with document inlines to highlight formatted content (bold text, links).MediaPlayerElement (available when you reference the media package) embeds audio/video playback with transport controls.
Source to URIs or streams; the element manages decoding via platform backends (Windows uses Angle/DX, Linux goes through FFmpeg when available).AreTransportControlsEnabled to show built-in play/pause UI; for custom chrome, bind to MediaPlayer and drive commands yourself.MediaOpened/MediaEnded to chain playlists or update state.Create a ComponentGalleryWindow that showcases each control with explanations and theme toggles:
<TabControl>
<TabItem Header="Color">
<StackPanel Spacing="16">
<TextBlock Text="ColorPicker" FontWeight="SemiBold"/>
<ColorPicker SelectedColor="{Binding ThemeColor}"/>
</StackPanel>
</TabItem>
<TabItem Header="Refresh">
<ptr:RefreshContainer RefreshRequested="OnRefreshRequested">
<ListBox ItemsSource="{Binding Items}"/>
</ptr:RefreshContainer>
</TabItem>
<TabItem Header="Notifications">
<StackPanel>
<Button Content="Show success" Click="OnShowSuccess"/>
<TextBlock Text="Notifications appear top-right"/>
</StackPanel>
</TabItem>
</TabControl>
Best practices:
TextBlock or copy buttons so teammates can reuse patterns.ColorPicker palettes, bind to view model state, and expose automation peers for UI tests.RefreshContainer in a list, test on touch-enabled hardware, and add fallback commands for desktop.SplitView, SplitButton, and TransitioningContentControl to create a responsive navigation shell with keyboard and pointer parity.PART_*). When restyling, preserve these names or update code-behind references.WindowNotificationManager with dozens of toasts.RefreshContainer needs a ScrollViewer or adapter implementing IRefreshInfoProvider; custom panels must adapt to supply offset data.DateTimeOffset. When binding to DateTime, convert carefully to retain time zones.HorizontalAlignment.Stretch; consider fixed width.external/Avalonia/src/Avalonia.Controls.ColorPicker/ColorPicker/ColorPicker.csexternal/Avalonia/src/Avalonia.Controls/PullToRefresh/RefreshContainer.csexternal/Avalonia/src/Avalonia.Controls/Notifications/WindowNotificationManager.cs, NotificationCard.csexternal/Avalonia/src/Avalonia.Controls/Calendar/Calendar.cs, external/Avalonia/src/Avalonia.Controls/DateTimePickers/DatePicker.cs, TimePicker.csexternal/Avalonia/src/Avalonia.Controls/SplitView/SplitView.cs, external/Avalonia/src/Avalonia.Controls/SplitButton/SplitButton.csexternal/Avalonia/src/Avalonia.Controls/Documents/*external/Avalonia/src/Avalonia.Controls/TransitioningContentControl.csRefreshContainer, and why does it need a RefreshVisualizer?WindowNotificationManager limit concurrent notifications and close them programmatically?DatePicker in sync with DateTime view-model properties?SplitView for light-dismiss overlay vs inline mode?What's next