Primary APIs:
AutomationPropertiesAutomationPeerControlAutomationPeerAutomationControlTypeAutomationLiveSettingControl.OnCreateAutomationPeer()Important members:
AutomationProperties.SetName/GetNameAutomationProperties.SetAutomationId/GetAutomationIdAutomationProperties.SetHelpText/GetHelpTextAutomationProperties.SetLabeledBy/GetLabeledByAutomationProperties.SetControlTypeOverride/GetControlTypeOverrideAutomationProperties.SetLiveSetting/GetLiveSettingAutomationProperties.SetAccessKey/GetAccessKeyAutomationPeer.GetName(), GetAutomationId(), GetAutomationControlType()AutomationPeer.GetHelpText(), GetLabeledBy(), GetLiveSetting()ControlAutomationPeer.CreatePeerForElement(...)Reference source files:
src/Avalonia.Controls/Automation/AutomationProperties.cssrc/Avalonia.Controls/Automation/Peers/AutomationPeer.cssrc/Avalonia.Controls/Automation/Peers/ControlAutomationPeer.cssrc/Avalonia.Controls/Automation/AutomationLiveSetting.cssrc/Avalonia.Controls/Control.csModel summary:
OnCreateAutomationPeer).AutomationProperties attached properties provide defaults and overrides.<TextBox
AutomationProperties.Name="Email"
AutomationProperties.AutomationId="EmailInput"
AutomationProperties.HelpText="Enter your work email" />
<Label x:Name="EmailLabel" Content="_Email" Target="{Binding #EmailBox}" />
<TextBox x:Name="EmailBox"
AutomationProperties.LabeledBy="{Binding #EmailLabel}" />
using Avalonia.Automation.Peers;
using Avalonia.Controls;
public class StatusBadge : Control
{
protected override AutomationPeer OnCreateAutomationPeer()
=> new StatusBadgeAutomationPeer(this);
}
public sealed class StatusBadgeAutomationPeer : ControlAutomationPeer
{
public StatusBadgeAutomationPeer(StatusBadge owner) : base(owner) { }
protected override AutomationControlType GetAutomationControlTypeCore()
=> AutomationControlType.Group;
protected override string? GetNameCore()
=> AutomationProperties.GetName(Owner) ?? "Status";
}
AutomationProperties.Name for actionable controls.AutomationId stable for test automation and assistive tooling.LabeledBy for form controls when label text is not part of control content.LiveSetting only for true live regions to avoid noisy announcements.AutomationProperties.Name missing and peer fallback is weak.ControlTypeOverride for custom interaction model.LiveSetting not set or content changes not represented in peer-visible properties.Default mode:
XAML-first complete example:
<StackPanel xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Spacing="8">
<Label x:Name="EmailLabel" Content="_Email" Target="{Binding #EmailBox}" />
<TextBox x:Name="EmailBox"
AutomationProperties.Name="Email"
AutomationProperties.AutomationId="EmailInput"
AutomationProperties.LabeledBy="{Binding #EmailLabel}" />
</StackPanel>
Code-only alternative (on request):
using Avalonia.Automation;
AutomationProperties.SetName(emailBox, "Email");
AutomationProperties.SetAutomationId(emailBox, "EmailInput");
AutomationProperties.SetHelpText(emailBox, "Enter your work email address");
AutomationProperties.SetLabeledBy(emailBox, emailLabel);