From facc253b21a848644b5d0469019803c57ffa3f9e Mon Sep 17 00:00:00 2001 From: Jumar Macato <16554748+jmacato@users.noreply.github.com> Date: Fri, 3 Jul 2026 03:20:20 +0800 Subject: [PATCH] Convert ExpandCollapseState to its UIA wire value in the Win32 automation layer; Avalonia declares PartiallyExpanded and LeafNode in the opposite order from UIA. (#21693) --- .../AutomationNode.ExpandCollapse.cs | 15 +++++++++++++-- .../Avalonia.Win32.Automation/AutomationNode.cs | 4 ++-- .../Interop/IExpandCollapseProvider.cs | 3 +-- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/Windows/Avalonia.Win32.Automation/AutomationNode.ExpandCollapse.cs b/src/Windows/Avalonia.Win32.Automation/AutomationNode.ExpandCollapse.cs index c28d000f56..200d1c93a9 100644 --- a/src/Windows/Avalonia.Win32.Automation/AutomationNode.ExpandCollapse.cs +++ b/src/Windows/Avalonia.Win32.Automation/AutomationNode.ExpandCollapse.cs @@ -6,11 +6,22 @@ namespace Avalonia.Win32.Automation { internal partial class AutomationNode : UIA.IExpandCollapseProvider { - ExpandCollapseState UIA.IExpandCollapseProvider.GetExpandCollapseState() + int UIA.IExpandCollapseProvider.GetExpandCollapseState() { - return InvokeSync(x => x.ExpandCollapseState); + return ToUiaExpandCollapseState(InvokeSync(x => x.ExpandCollapseState)); } + // Avalonia declares PartiallyExpanded and LeafNode in the opposite order + // from the UIA wire values. + internal static int ToUiaExpandCollapseState(ExpandCollapseState state) => state switch + { + ExpandCollapseState.Collapsed => 0, + ExpandCollapseState.Expanded => 1, + ExpandCollapseState.PartiallyExpanded => 2, + ExpandCollapseState.LeafNode => 3, + _ => 0, + }; + void UIA.IExpandCollapseProvider.Expand() => InvokeSync(x => x.Expand()); void UIA.IExpandCollapseProvider.Collapse() => InvokeSync(x => x.Collapse()); } diff --git a/src/Windows/Avalonia.Win32.Automation/AutomationNode.cs b/src/Windows/Avalonia.Win32.Automation/AutomationNode.cs index e2ffca2ea7..1c0236e8c0 100644 --- a/src/Windows/Avalonia.Win32.Automation/AutomationNode.cs +++ b/src/Windows/Avalonia.Win32.Automation/AutomationNode.cs @@ -301,8 +301,8 @@ namespace Avalonia.Win32.Automation UiaCoreProviderApi.UiaRaiseAutomationPropertyChangedEvent( this, (int)id, - e.OldValue as IConvertible, - e.NewValue as IConvertible); + e.OldValue is ExpandCollapseState o ? ToUiaExpandCollapseState(o) : e.OldValue as IConvertible, + e.NewValue is ExpandCollapseState n ? ToUiaExpandCollapseState(n) : e.NewValue as IConvertible); } if (id == UiaPropertyId.Name && Peer.GetLiveSetting() != AutomationLiveSetting.Off) diff --git a/src/Windows/Avalonia.Win32.Automation/Interop/IExpandCollapseProvider.cs b/src/Windows/Avalonia.Win32.Automation/Interop/IExpandCollapseProvider.cs index 7e5cc048de..2621edf28e 100644 --- a/src/Windows/Avalonia.Win32.Automation/Interop/IExpandCollapseProvider.cs +++ b/src/Windows/Avalonia.Win32.Automation/Interop/IExpandCollapseProvider.cs @@ -1,6 +1,5 @@ using System.Runtime.InteropServices; using System.Runtime.InteropServices.Marshalling; -using Avalonia.Automation; namespace Avalonia.Win32.Automation.Interop; @@ -10,5 +9,5 @@ internal partial interface IExpandCollapseProvider { void Expand(); void Collapse(); - ExpandCollapseState GetExpandCollapseState(); + int GetExpandCollapseState(); }