Browse Source

Merge pull request #11523 from AvaloniaUI/feature/peer-from-element

Added ControlAutomationPeer.FromElement.
pull/11532/head
Max Katz 3 years ago
committed by GitHub
parent
commit
d77760e2c1
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 20
      src/Avalonia.Controls/Automation/Peers/ControlAutomationPeer.cs
  2. 6
      src/Avalonia.Controls/Control.cs

20
src/Avalonia.Controls/Automation/Peers/ControlAutomationPeer.cs

@ -31,11 +31,31 @@ namespace Avalonia.Automation.Peers
return CreatePeerForElement(element);
}
/// <summary>
/// Gets the <see cref="AutomationPeer"/> for a <see cref="Control"/>, creating it if
/// necessary.
/// </summary>
/// <param name="element">The control.</param>
/// <returns>The automation peer.</returns>
/// <remarks>
/// Despite the name (which comes from the analogous WPF API), this method does not create
/// a new peer if one already exists: instead it returns the existing peer.
/// </remarks>
public static AutomationPeer CreatePeerForElement(Control element)
{
return element.GetOrCreateAutomationPeer();
}
/// <summary>
/// Gets an existing <see cref="AutomationPeer"/> for a <see cref="Control"/>.
/// </summary>
/// <param name="element">The control.</param>
/// <returns>The automation peer if already created; otherwise null.</returns>
/// <remarks>
/// To ensure that a peer is created, use <see cref="CreatePeerForElement(Control)"/>.
/// </remarks>
public static AutomationPeer? FromElement(Control element) => element.GetAutomationPeer();
protected override void BringIntoViewCore() => Owner.BringIntoView();
protected override IReadOnlyList<AutomationPeer> GetOrCreateChildrenCore()

6
src/Avalonia.Controls/Control.cs

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

Loading…
Cancel
Save