页面上的某些控件对于MS UI Automation不可见 [英] Some controls on a page are not visible for MS UI Automation

查看:158
本文介绍了页面上的某些控件对于MS UI Automation不可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个带有StartPage.xaml的应用程序,其中TabControl的控件模板定义了一些网格和堆栈面板.在xaml的中间,该模板中有一个itemPresenter,在其下方有一个堆栈面板.虽然对用户来说工作正常,但MS UI自动化只能在项目演示者内部看到选项卡项目,而在模板的同一级别上没有定义其他任何项目. 我试图将标准按钮添加到MS UIA无法看到的堆栈面板中,以检查这是否与我们拥有的自定义用户控件有关,但该标准按钮对于MS UIA也不可见. 如果使用Snoop,则可以在模板层次结构的相应级别上的snoop的树中看到模板中的所有元素.但是MS UIA仍然找不到它们.

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.

使用控件会导致MS UIA在页面上找不到它们的地方会出什么问题?

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

推荐答案

最后,我能够检测到该问题. TabControl具有许多不同的控件作为模板,而AutomationPeer保持不变,它仅将TabItem视为TabControl子级. 我将TabControl子类化,并覆盖OnCreateAutomation来创建并返回GenericAutomationPeer,该GenericAutomationPeer可以枚举此控件和子控件的所有子UIElement-UIA验证现在可以从TabControl模板中看到其他控件.

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实现在此处找到: http://www. colinsalmcorner.com/2011/11/genericautomationpeer-helping-coded-ui.html 非常感谢那篇文章的作者!

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

这篇关于页面上的某些控件对于MS UI Automation不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆