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

6
src/Avalonia.Controls/Control.cs

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

Loading…
Cancel
Save