简体   繁体   English

WPF UI自动化-在单击TabControl的区域之前,控制树不会出现问题

[英]WPF UI Automation - Control Tree not poluated till region is clicked for a TabControl

I am doing a UI automation for a WPF application using the Microsoft UI Automation library and it works well. 我正在使用Microsoft UI自动化库为WPF应用程序进行UI自动化,并且运行良好。

However my app has four screens in a TabControl. 但是我的应用程序在TabControl中有四个屏幕。 Even when I click the tab item through code its child control tree isnt populated. 即使当我通过代码单击选项卡项目时,也不会填充其子控件树。 The only control I can see is the "thumb" Control. 我可以看到的唯一控件是“拇指”控件。 Same happens when I see the control tree with UISpy. 当我看到带有UISpy的控件树时,也会发生同样的情况。

However if the window is clicked then all the controls appear. 但是,如果单击该窗口,则会显示所有控件。 As a Workaround I am simulating a mouseclick through code and it works. 作为一种解决方法,我通过代码模拟了鼠标单击,并且可以正常工作。 I wanted to know if there is some better way of doing it. 我想知道是否有更好的方法。

I ran into a problem similar to this. 我遇到了与此类似的问题。 What was happening was some data was being retrieved on threads and the controls were not generated at the point automation peers were generated. 发生的事情是在线程上检索了一些数据,并且在生成自动化对等点时未生成控件。 I would suggest if you have access to the code base for the application you are attempting to automate looking into whether threading is being used. 我建议您是否有权访问应用程序的代码库,以尝试自动查看是否正在使用线程。 In my specific case it was because BeginInvokes were used to retrieve the data, I switched them to Invokes and it worked fine. 在我的特定情况下,这是因为使用BeginInvokes来检索数据,所以我将它们切换为Invokes,并且运行良好。

Also from what I could tell the reason the controls were being show on mouse over was because the tool tip generated a popup and caused the automation peers to be updated. 同样,我可以说出鼠标悬停时显示控件的原因是因为工具提示生成了一个弹出窗口,并导致了自动化对等项的更新。

Why don't you click the control using mouse events if that is what works. 如果可以的话,为什么不使用鼠标事件单击控件。

(Now, if you still are having that problem..) (现在,如果您仍然遇到该问题。)

How to simulate Mouse Click in C#? 如何在C#中模拟鼠标单击?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM