From de50cda755d2cd14510db5b6b4f6719e0a3a69aa Mon Sep 17 00:00:00 2001 From: Daniil Pavliuchyk Date: Thu, 2 Mar 2023 13:04:02 +0200 Subject: [PATCH] Add LabelAutomationPeer --- .../Automation/Peers/LabelAutomationPeer.cs | 27 +++++++++++++++++++ src/Avalonia.Controls/Label.cs | 7 +++++ 2 files changed, 34 insertions(+) create mode 100644 src/Avalonia.Controls/Automation/Peers/LabelAutomationPeer.cs diff --git a/src/Avalonia.Controls/Automation/Peers/LabelAutomationPeer.cs b/src/Avalonia.Controls/Automation/Peers/LabelAutomationPeer.cs new file mode 100644 index 0000000000..4ea950df7e --- /dev/null +++ b/src/Avalonia.Controls/Automation/Peers/LabelAutomationPeer.cs @@ -0,0 +1,27 @@ +using Avalonia.Automation.Peers; +using Avalonia.Controls.Primitives; + +namespace Avalonia.Controls.Automation.Peers +{ + public class LabelAutomationPeer : ControlAutomationPeer + { + public LabelAutomationPeer(Label owner) : base(owner) + { + } + + override protected string GetClassNameCore() + { + return "Text"; + } + + override protected AutomationControlType GetAutomationControlTypeCore() + { + return AutomationControlType.Text; + } + + override protected string GetNameCore() + { + return AccessText.RemoveAccessKeyMarker(((Label)Owner).Content as string) ?? string.Empty; + } + } +} diff --git a/src/Avalonia.Controls/Label.cs b/src/Avalonia.Controls/Label.cs index 5c8a6e0a5b..cabbb5adf7 100644 --- a/src/Avalonia.Controls/Label.cs +++ b/src/Avalonia.Controls/Label.cs @@ -2,6 +2,8 @@ using System.Collections.Generic; using System.Runtime.CompilerServices; using System.Text; +using Avalonia.Automation.Peers; +using Avalonia.Controls.Automation.Peers; using Avalonia.Controls.Primitives; using Avalonia.Controls.Templates; using Avalonia.Data; @@ -71,5 +73,10 @@ namespace Avalonia.Controls } base.OnPointerPressed(e); } + + protected override AutomationPeer OnCreateAutomationPeer() + { + return new LabelAutomationPeer(this); + } } }