Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Some controls on a page are not visible for MS UI Automation

We have an application with StartPage.xaml, where control template for TabControl defines some grids and stack panels. There is an itemPresenter in that template in the middle of the xaml, and a stack panel below it. While it works fine for a user, MS UI automation can see only tab items inside the item presenter, and nothing else that is defined on the same level in the template. I tried to add standard button inside a stack panel which can not be seen by MS UIA to check if that is a problem related to custom user controls we have, but that standard button is also not visible for MS UIA. If I use Snoop, I can see all the elements from the template in a snoop's tree on the corresponding levels of template hierarchy. But MS UIA still can't find them.

What can go wrong here with controls that will prevent MS UIA from finding them on a page?

like image 686
DarkDeny Avatar asked May 28 '13 13:05

DarkDeny


1 Answers

Finally I was able to detect the problem. TabControl was templated with a bunch of different controls, while AutomationPeer stayed the same which is only aware of TabItems as TabControl children. I subclassed TabControl and overrode OnCreateAutomation to create and return my GenericAutomationPeer, which can enumerate all child UIElements of this control and voila - UIA Verify can now see that additional controls from TabControl template.

GenericAutomationPeer implementation was found here: http://www.colinsalmcorner.com/2011/11/genericautomationpeer-helping-coded-ui.html Great thanks to the author of that article!

like image 91
DarkDeny Avatar answered Sep 23 '22 12:09

DarkDeny