Repository navigation
Description
Current behavior 🐛
AutomationPeer.GetClassName() returns the bare type name (for example "InfoBar") for the automation peers of 19 controls that come from the WinUI controls library (the former WinUI 2 / MUX controls):
AnimatedVisualPlayer, BreadcrumbBarItem, ColorSpectrum, InfoBar, ItemContainer, ItemsView, MenuBarItem, NavigationViewItem, PagerControl, PersonPicture, PipsPager, ProgressRing, SelectorBarItem, TabView, TabViewItem, TeachingTip, TitleBar, TreeViewItem, WebView2.
Other peers ported from the same library already return the fully-qualified name: Expander, NumberBox, SplitButton, ToggleSplitButton, DropDownButton, RadioButtons, ProgressBar.
Expected behavior 🎯
Like WinUI, these peers should return the namespace-qualified runtime class name, e.g. "Microsoft.UI.Xaml.Controls.InfoBar" (and "Microsoft.UI.Xaml.Controls.Primitives.ColorSpectrum" for ColorSpectrum).
In WinUI every one of these peers implements GetClassNameCore as return winrt::hstring_name_of<winrt::T>();, and hstring_name_of is hstring(winrt::name_of<T>()), the fully-qualified WinRT class name (CppWinRTHelpers.h). Examples:
- InfoBarAutomationPeer.cpp
- TabViewItemAutomationPeer.cpp
- NavigationViewItemAutomationPeer.cpp
- TreeViewItemAutomationPeer.cpp
The same pattern is used in controls/dev/* for all 19 controls listed above.
Note: this only applies to the controls-library peers. Core peers (e.g. ButtonAutomationPeer in dxaml/xcp) return a short name like L"Button" in WinUI too, so they are not affected.
How to reproduce it (as minimally and precisely as possible) 🔬
- Create a new Uno app (
dotnet new unoapp) and run it on any Skia target. - Run this code (e.g. in a button click handler) and look at the output:
using Microsoft.UI.Xaml.Automation.Peers;
using Microsoft.UI.Xaml.Controls;
var peer = FrameworkElementAutomationPeer.CreatePeerForElement(new InfoBar());
System.Diagnostics.Debug.WriteLine(peer.GetClassName());
// Uno: InfoBar
// WinUI: Microsoft.UI.Xaml.Controls.InfoBar
var expander = FrameworkElementAutomationPeer.CreatePeerForElement(new Expander());
System.Diagnostics.Debug.WriteLine(expander.GetClassName());
// Uno and WinUI: Microsoft.UI.Xaml.Controls.ExpanderA runtime test that checks all 19 controls (plus Expander and NumberBox as controls) fails on Skia Desktop on current master with 19 mismatches:
FAIL AnimatedVisualPlayerAutomationPeer: GetClassName()="AnimatedVisualPlayer" expected "Microsoft.UI.Xaml.Controls.AnimatedVisualPlayer"
FAIL BreadcrumbBarItemAutomationPeer: GetClassName()="BreadcrumbBarItem" expected "Microsoft.UI.Xaml.Controls.BreadcrumbBarItem"
FAIL ColorSpectrumAutomationPeer: GetClassName()="ColorSpectrum" expected "Microsoft.UI.Xaml.Controls.Primitives.ColorSpectrum"
FAIL InfoBarAutomationPeer: GetClassName()="InfoBar" expected "Microsoft.UI.Xaml.Controls.InfoBar"
FAIL ItemContainerAutomationPeer: GetClassName()="ItemContainer" expected "Microsoft.UI.Xaml.Controls.ItemContainer"
FAIL ItemsViewAutomationPeer: GetClassName()="ItemsView" expected "Microsoft.UI.Xaml.Controls.ItemsView"
FAIL MenuBarItemAutomationPeer: GetClassName()="MenuBarItem" expected "Microsoft.UI.Xaml.Controls.MenuBarItem"
FAIL NavigationViewItemAutomationPeer: GetClassName()="NavigationViewItem" expected "Microsoft.UI.Xaml.Controls.NavigationViewItem"
FAIL PagerControlAutomationPeer: GetClassName()="PagerControl" expected "Microsoft.UI.Xaml.Controls.PagerControl"
FAIL PersonPictureAutomationPeer: GetClassName()="PersonPicture" expected "Microsoft.UI.Xaml.Controls.PersonPicture"
FAIL PipsPagerAutomationPeer: GetClassName()="PipsPager" expected "Microsoft.UI.Xaml.Controls.PipsPager"
FAIL ProgressRingAutomationPeer: GetClassName()="ProgressRing" expected "Microsoft.UI.Xaml.Controls.ProgressRing"
FAIL SelectorBarItemAutomationPeer: GetClassName()="SelectorBarItem" expected "Microsoft.UI.Xaml.Controls.SelectorBarItem"
FAIL TabViewAutomationPeer: GetClassName()="TabView" expected "Microsoft.UI.Xaml.Controls.TabView"
FAIL TabViewItemAutomationPeer: GetClassName()="TabViewItem" expected "Microsoft.UI.Xaml.Controls.TabViewItem"
FAIL TeachingTipAutomationPeer: GetClassName()="TeachingTip" expected "Microsoft.UI.Xaml.Controls.TeachingTip"
FAIL TitleBarAutomationPeer: GetClassName()="TitleBar" expected "Microsoft.UI.Xaml.Controls.TitleBar"
FAIL TreeViewItemAutomationPeer: GetClassName()="TreeViewItem" expected "Microsoft.UI.Xaml.Controls.TreeViewItem"
FAIL WebView2AutomationPeer: GetClassName()="WebView2" expected "Microsoft.UI.Xaml.Controls.WebView2"
OK ExpanderAutomationPeer: GetClassName()="Microsoft.UI.Xaml.Controls.Expander" expected "Microsoft.UI.Xaml.Controls.Expander"
OK NumberBoxAutomationPeer: GetClassName()="Microsoft.UI.Xaml.Controls.NumberBox" expected "Microsoft.UI.Xaml.Controls.NumberBox"
Workaround 🛠️
Subclass the control, override OnCreateAutomationPeer, and return a derived peer whose GetClassNameCore() returns typeof(TControl).FullName.
Renderer 🎨
- Skia
- Native
Affected platforms 📱💻🖥️
All platforms 🌍 (except Windows App SDK)
Uno.Sdk version (and other relevant versions) 📦
Current master (bfc8dff), runtime test run on Skia Desktop (Windows).
IDE version 🧑💻
No response
Anything else we need to know? 💬
Evidence: the WinUI behavior is backed by the WinUI C++ sources linked above (no native WinUI run). The Uno behavior is backed by a runtime test on Skia Desktop.
Root cause: when these peers were ported, winrt::hstring_name_of<winrt::T>() was translated to nameof(T) (short name) instead of typeof(T).FullName (as done for Expander, NumberBox, SplitButton, etc.). For example:
- InfoBarAutomationPeer.cs
- TabViewItemAutomationPeer.cs
- compared with the correct ExpanderAutomationPeer.cs
Suggested fix: in each affected GetClassNameCore, replace nameof(T) with typeof(T).FullName!. Files on master:
src/Uno.UI/UI/Xaml/Automation/Peers/AnimatedVisualPlayerAutomationPeer.cssrc/Uno.UI/UI/Xaml/Automation/Peers/WebView2AutomationPeer.cssrc/Uno.UI/UI/Xaml/Controls/BreadcrumbBar/BreadcrumbBarItemAutomationPeer.cssrc/Uno.UI/UI/Xaml/Controls/ColorPicker/ColorSpectrumAutomationPeer.cssrc/Uno.UI/UI/Xaml/Controls/InfoBar/InfoBarAutomationPeer.cssrc/Uno.UI/UI/Xaml/Controls/ItemContainer/ItemContainerAutomationPeer.cssrc/Uno.UI/UI/Xaml/Controls/ItemsView/ItemsViewAutomationPeer.cs(a fix for this one is in progress)src/Uno.UI/UI/Xaml/Controls/MenuBar/MenuBarItemAutomationPeer.cssrc/Uno.UI/UI/Xaml/Controls/NavigationView/NavigationViewItemAutomationPeer.cssrc/Uno.UI/UI/Xaml/Controls/PagerControl/PagerControlAutomationPeer.cssrc/Uno.UI/UI/Xaml/Controls/PersonPicture/PersonPictureAutomationPeer.cssrc/Uno.UI/UI/Xaml/Controls/PipsPager/PipsPagerAutomationPeer.cssrc/Uno.UI/UI/Xaml/Controls/ProgressRing/ProgressRingAutomationPeer.cssrc/Uno.UI/UI/Xaml/Controls/SelectorBar/SelectorBarItemAutomationPeer.cssrc/Uno.UI/UI/Xaml/Controls/TabView/TabViewAutomationPeer.cssrc/Uno.UI/UI/Xaml/Controls/TabView/TabViewItemAutomationPeer.cssrc/Uno.UI/UI/Xaml/Controls/TeachingTip/TeachingTipAutomationPeer.cssrc/Uno.UI/UI/Xaml/Controls/TitleBar/TitleBarAutomationPeer.mux.cssrc/Uno.UI/UI/Xaml/Controls/TreeView/TreeViewItemAutomationPeer.cs
A runtime test can create each control, call FrameworkElementAutomationPeer.CreatePeerForElement(control).GetClassName(), and compare it with control.GetType().FullName.
Impact: UI automation scripts and accessibility tools that key on the UIA ClassName property see different values on Uno than on WinUI for these controls.
Activity