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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
26 additions and
0 deletions
-
src/Avalonia.Controls/Automation/Peers/ControlAutomationPeer.cs
-
src/Avalonia.Controls/Control.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() |
|
|
|
|
|
|
|
@ -440,6 +440,12 @@ namespace Avalonia.Controls |
|
|
|
return new NoneAutomationPeer(this); |
|
|
|
} |
|
|
|
|
|
|
|
internal AutomationPeer? GetAutomationPeer() |
|
|
|
{ |
|
|
|
VerifyAccess(); |
|
|
|
return _automationPeer; |
|
|
|
} |
|
|
|
|
|
|
|
internal AutomationPeer GetOrCreateAutomationPeer() |
|
|
|
{ |
|
|
|
VerifyAccess(); |
|
|
|
|