Browse Source

Try to fix problem with ComboBox.

Only the OS can create the root automation peer, so we need to take care to not accidentally try to create it from `PopupAutomationPeer`.
ui-automation-test
Steven Kirk 5 years ago
parent
commit
c34a825bf5
  1. 11
      src/Avalonia.Controls/Automation/Peers/PopupAutomationPeer.cs
  2. 6
      src/Avalonia.Controls/Control.cs

11
src/Avalonia.Controls/Automation/Peers/PopupAutomationPeer.cs

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using Avalonia.Automation.Platform; using Avalonia.Automation.Platform;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Controls.Diagnostics;
using Avalonia.Controls.Primitives; using Avalonia.Controls.Primitives;
using Avalonia.VisualTree; using Avalonia.VisualTree;
@ -20,9 +21,9 @@ namespace Avalonia.Automation.Peers
protected override IReadOnlyList<AutomationPeer>? GetChildrenCore() protected override IReadOnlyList<AutomationPeer>? GetChildrenCore()
{ {
var host = (IVisualTreeHost)Owner; var popupHost = ((IPopupHostProvider)Owner)?.PopupHost as Control;
System.Diagnostics.Debug.WriteLine($"Popup children='{host}'"); var hostPeer = popupHost?.GetAutomationPeer();
return host.Root is Control c ? new[] { GetOrCreatePeer(c) } : null; return hostPeer is object ? new[] { hostPeer } : null;
} }
protected override bool IsContentElementCore() => false; protected override bool IsContentElementCore() => false;
@ -45,8 +46,8 @@ namespace Avalonia.Automation.Peers
private AutomationPeer? GetPopupRoot() private AutomationPeer? GetPopupRoot()
{ {
var popupRoot = ((IVisualTreeHost)Owner).Root as Control; var popupRoot = ((IPopupHostProvider)Owner).PopupHost as Control;
return popupRoot is object ? GetOrCreatePeer(popupRoot) : null; return popupRoot?.GetAutomationPeer();
} }
} }
} }

6
src/Avalonia.Controls/Control.cs

@ -235,6 +235,12 @@ namespace Avalonia.Controls
return new NoneAutomationPeer(factory, this); return new NoneAutomationPeer(factory, this);
} }
internal AutomationPeer? GetAutomationPeer()
{
VerifyAccess();
return _automationPeer;
}
internal AutomationPeer GetOrCreateAutomationPeer(IAutomationNodeFactory factory) internal AutomationPeer GetOrCreateAutomationPeer(IAutomationNodeFactory factory)
{ {
VerifyAccess(); VerifyAccess();

Loading…
Cancel
Save