From de50cda755d2cd14510db5b6b4f6719e0a3a69aa Mon Sep 17 00:00:00 2001 From: Daniil Pavliuchyk Date: Thu, 2 Mar 2023 13:04:02 +0200 Subject: [PATCH 1/3] 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); + } } } From b65933b9d6b2cc88b541ea9ab5f911d85f3bd1bb Mon Sep 17 00:00:00 2001 From: Daniil Pavliuchyk Date: Thu, 2 Mar 2023 14:11:17 +0200 Subject: [PATCH 2/3] Update GetNameCore logic to match WPF logic --- .../Automation/Peers/LabelAutomationPeer.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Avalonia.Controls/Automation/Peers/LabelAutomationPeer.cs b/src/Avalonia.Controls/Automation/Peers/LabelAutomationPeer.cs index 4ea950df7e..86cd0d5b14 100644 --- a/src/Avalonia.Controls/Automation/Peers/LabelAutomationPeer.cs +++ b/src/Avalonia.Controls/Automation/Peers/LabelAutomationPeer.cs @@ -19,9 +19,16 @@ namespace Avalonia.Controls.Automation.Peers return AutomationControlType.Text; } - override protected string GetNameCore() + override protected string? GetNameCore() { - return AccessText.RemoveAccessKeyMarker(((Label)Owner).Content as string) ?? string.Empty; + var content = ((Label)Owner).Content as string; + + if (string.IsNullOrEmpty(content)) + { + return base.GetNameCore(); + } + + return AccessText.RemoveAccessKeyMarker(content) ?? string.Empty; } } } From 8cb4cf8344fa0c84ac65defb9761e940827cddd5 Mon Sep 17 00:00:00 2001 From: Daniil Pavliuchyk Date: Thu, 2 Mar 2023 20:47:59 +0200 Subject: [PATCH 3/3] Remove unneccessary using directives. --- src/Avalonia.Controls/Label.cs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/Avalonia.Controls/Label.cs b/src/Avalonia.Controls/Label.cs index 6c6518f3ed..94ea66c4c1 100644 --- a/src/Avalonia.Controls/Label.cs +++ b/src/Avalonia.Controls/Label.cs @@ -1,12 +1,5 @@ -using System; -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; using Avalonia.Input; using Avalonia.Interactivity;