diff --git a/src/Avalonia.Controls/Automation/Peers/ToggleButtonAutomationPeer.cs b/src/Avalonia.Controls/Automation/Peers/ToggleButtonAutomationPeer.cs
index 979d54f48e..99b3cdd657 100644
--- a/src/Avalonia.Controls/Automation/Peers/ToggleButtonAutomationPeer.cs
+++ b/src/Avalonia.Controls/Automation/Peers/ToggleButtonAutomationPeer.cs
@@ -1,4 +1,5 @@
using Avalonia.Automation.Provider;
+using Avalonia.Controls.Automation;
using Avalonia.Controls.Primitives;
namespace Avalonia.Automation.Peers
@@ -8,19 +9,28 @@ namespace Avalonia.Automation.Peers
public ToggleButtonAutomationPeer(ToggleButton owner)
: base(owner)
{
+ Owner.PropertyChanged += (a, e) =>
+ {
+ if (e.Property == ToggleButton.IsCheckedProperty)
+ {
+ RaisePropertyChangedEvent(
+ TogglePatternIdentifiers.ToggleStateProperty,
+ ToState((bool?)e.OldValue),
+ ToState((bool?)e.NewValue));
+ }
+ };
}
public new ToggleButton Owner => (ToggleButton)base.Owner;
- ToggleState IToggleProvider.ToggleState
+ private ToggleState ToState(bool? value) => value switch
{
- get => Owner.IsChecked switch
- {
- true => ToggleState.On,
- false => ToggleState.Off,
- null => ToggleState.Indeterminate,
- };
- }
+ true => ToggleState.On,
+ false => ToggleState.Off,
+ null => ToggleState.Indeterminate,
+ };
+
+ ToggleState IToggleProvider.ToggleState => ToState(Owner.IsChecked);
void IToggleProvider.Toggle()
{
diff --git a/src/Avalonia.Controls/Automation/TogglePatternIdentifiers.cs b/src/Avalonia.Controls/Automation/TogglePatternIdentifiers.cs
new file mode 100644
index 0000000000..be6b1c8fb2
--- /dev/null
+++ b/src/Avalonia.Controls/Automation/TogglePatternIdentifiers.cs
@@ -0,0 +1,15 @@
+using Avalonia.Automation.Provider;
+
+namespace Avalonia.Automation
+{
+ ///
+ /// Contains values used as identifiers by .
+ ///
+ public static class TogglePatternIdentifiers
+ {
+ ///
+ /// Identifies the property.
+ ///
+ public static AutomationProperty ToggleStateProperty { get; } = new AutomationProperty();
+ }
+}
diff --git a/src/Windows/Avalonia.Win32.Automation/AutomationNode.cs b/src/Windows/Avalonia.Win32.Automation/AutomationNode.cs
index 45216a4c09..fea4ca3ef3 100644
--- a/src/Windows/Avalonia.Win32.Automation/AutomationNode.cs
+++ b/src/Windows/Avalonia.Win32.Automation/AutomationNode.cs
@@ -54,10 +54,8 @@ namespace Avalonia.Win32.Automation
{ SelectionPatternIdentifiers.IsSelectionRequiredProperty, UiaPropertyId.SelectionIsSelectionRequired },
{ SelectionPatternIdentifiers.SelectionProperty, UiaPropertyId.SelectionSelection },
{ SelectionItemPatternIdentifiers.IsSelectedProperty, UiaPropertyId.SelectionItemIsSelected },
- {
- SelectionItemPatternIdentifiers.SelectionContainerProperty,
- UiaPropertyId.SelectionItemSelectionContainer
- }
+ { SelectionItemPatternIdentifiers.SelectionContainerProperty, UiaPropertyId.SelectionItemSelectionContainer },
+ { TogglePatternIdentifiers.ToggleStateProperty, UiaPropertyId.ToggleToggleState },
};
private static ConditionalWeakTable s_nodes = new();