我尽可能地简化了这个问题,下面的代码可以剪切并粘贴到'test.linq'文件中并加载到LinqPad中。在运行时,LinqPad中的代码将显示它正常工作 - 目的是使用UI自动化框架找到带有AutomationId tabPage1
的窗格。
现在注释掉工作线并引入虚线。现在无法找到标签页...唯一的区别是标签页是用Text
属性声明的。
我找到了一个series of blogs 可能表明错误在于TabControl
已经反编译TabControl
来源的自动化提供商看不到这种情况,但基础Control
实现了WM_GETOBJECT
的处理程序,我真的不确定它在哪里。
有什么想法吗?
<Query Kind="Statements">
<Reference><RuntimeDirectory>\WPF\UIAutomationClient.dll</Reference>
<Reference><RuntimeDirectory>\wpf\UIAutomationProvider.dll</Reference>
<Reference><RuntimeDirectory>\wpf\UIAutomationTypes.dll</Reference>
<Reference><RuntimeDirectory>\Accessibility.dll</Reference>
<Reference><RuntimeDirectory>\wpf\WindowsBase.dll</Reference>
<Reference><RuntimeDirectory>\System.Windows.Forms.dll</Reference>
<Reference><RuntimeDirectory>\System.Security.dll</Reference>
<Reference><RuntimeDirectory>\System.Configuration.dll</Reference>
<Reference><RuntimeDirectory>\System.Deployment.dll</Reference>
<Reference><RuntimeDirectory>\System.Runtime.Serialization.Formatters.Soap.dll</Reference>
<Namespace>System.Windows.Automation</Namespace>
<Namespace>System.Windows.Forms</Namespace>
</Query>
var tabControl = new TabControl();
tabControl.Name = "tabControl";
// Broken
//tabControl.TabPages.Add(new TabPage() { Name = "tabPage1", Text = "First Tab" });
// Working
tabControl.TabPages.Add(new TabPage() { Name = "tabPage1" });
var form = new Form() { Name = "Form1" };
form.Controls.Add(tabControl);
form.Show();
var desktop = AutomationElement.RootElement;
var frmTest = desktop.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.AutomationIdProperty, "Form1"));
var tabPage1 = frmTest.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty, "tabPage1"));
tabPage1.Dump("tabPage1");