Repository navigation
Description
Current behavior 🐛
Several string attached properties on AutomationProperties are registered with default(string), so reading them on an element that never set them returns null:
var b = new Button();
AutomationProperties.GetHelpText(b); // null
AutomationProperties.GetAcceleratorKey(b); // nullAffected properties (all registered with new FrameworkPropertyMetadata(default(string)) in AutomationProperties.cs):
AcceleratorKey, AccessKey, FullDescription, HelpText, ItemStatus, ItemType, LocalizedControlType, LocalizedLandmarkType.
Only Name (and AutomationId) already default to "".
Expected behavior 🎯
Same as WinUI: the getters return string.Empty when the property was never set. In WinUI these are HSTRING attached properties declared without a default value (StaticMetadata.g.cpp: the AutomationProperties_AcceleratorKey etc. entries carry only type and flags, no default), and the getters just forward to GetValueByKnownIndex (AutomationProperties.cpp). An unset string reads as an empty HSTRING, which C# sees as "".
This is backed by WinUI C++ source inspection (no native WinUI run). WinUI-ported tests also rely on it, e.g. Verify.AreEqual(string.Empty, AutomationProperties.GetHelpText(element)).
How to reproduce it (as minimally and precisely as possible) 🔬
- Create any Uno app (Skia desktop is enough).
- Run:
var b = new Button();
Assert.AreEqual(string.Empty, AutomationProperties.GetHelpText(b)); // fails, actual: null
Assert.AreEqual(string.Empty, AutomationProperties.GetAcceleratorKey(b)); // fails, actual: null
// same for AccessKey, FullDescription, ItemStatus, ItemType, LocalizedControlType, LocalizedLandmarkType- Compare with WinUI, where all of these return
"".
Confirmed by code inspection on master at cc48541 (the registrations above). The effect was also hit at runtime on Skia desktop through ported WinUI tests that assert string.Empty for HelpText.
Workaround 🛠️
AutomationProperties.GetXxx(element) ?? string.Empty
Renderer 🎨
- Skia
- Native
Affected platforms 📱💻🖥️
All (shared Uno.UI code).
Uno.SDK version (and other relevant versions) 📦
master @ cc48541
IDE version 🧑💻
N/A
Anything else we need to know? 💬
Suggested fix: change the defaults to string.Empty and audit consumers that compare to null (e.g. AriaMapper and the automation peers). Most already use IsNullOrEmpty / ?? string.Empty. A fix for HelpText is in progress; the other seven properties still need the same change.
Activity