Added property changed event for IToggleProvider (#20486)

This commit is contained in:
Melissa
2026-01-19 11:32:38 +01:00
committed by GitHub
parent 2bcbbde723
commit a77f7adce0
3 changed files with 35 additions and 12 deletions
@@ -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()
{
@@ -0,0 +1,15 @@
using Avalonia.Automation.Provider;
namespace Avalonia.Automation
{
/// <summary>
/// Contains values used as identifiers by <see cref="IToggleProvider"/>.
/// </summary>
public static class TogglePatternIdentifiers
{
/// <summary>
/// Identifies the <see cref="IToggleProvider.ToggleState"/> property.
/// </summary>
public static AutomationProperty ToggleStateProperty { get; } = new AutomationProperty();
}
}
@@ -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<AutomationPeer, AutomationNode> s_nodes = new();