WinControl的本机对象类?

Kyl*_* V. 6 c# .net-4.0 coded-ui-tests

我正在尝试获取WinTable对象并将其转换为其本机对象类型:

CustomControl control = (CustomControl) this.UIMap.UIMainWindow.UICustomControl.NativeElement;
Run Code Online (Sandbox Code Playgroud)

然后我想像CustomControl我在程序的源代码中那样处理结果control.DoAThing(),我已经引用了包含CustomControl类的.dll 但问题.NativeElement;是返回一个类型Object[]而不是Object函数定义那样说它应该.

.NativeElement走的路还是我误解了它的目的?

更新:我检查了结果中对象的类型,Object[]第一个是类型System.__ComObject,第二个是System.Int32但是我不确定这些代表什么...

cla*_*b86 0

CustomControl如果您发布了您的代码和UICustomControl课程,这将会很有帮助。根据我对您的问题的模糊理解,以下方法可能有效:尝试一下并发布结果。

object[] native = 
  this.UIMap.UIMainWindow.UICustomControl.NativeElement as object[];
if ((native[0] != null) && (native[0] is IAccessible)) {
    IAccessible a = native[0] as IAccessible;
    if (a is CustomControl)
        CustomControl control = (CustomControl)a;
}
Run Code Online (Sandbox Code Playgroud)