Domanda

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?

È stato utile?

Soluzione

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!

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top