Cast Object as WPF Object
Hi,
i'm trying to use Testcomplete standard functions with an object received directly from a function call to a WPF/.net application on a request, rather than going through the usual Namemapping/Search tree.
It looks like this:
var obj = Aliases.App.Main.GetControl();
This obj can access all .net properties and methods just fine.
E.g. for a Button i can call
obj.OnClick();
However, if the button was received through namemapping like this:
var NMobj = Aliases.App.Main.ButtonTest;
I can also access e.g:
NMobj.Click();
Which doesn't work with "obj" because "this object doesn't support this method".
So my question is: is there any possibility to tell Testcomplete, that "obj" is a WPFButton, to make all the usual methods available?
I tried FindChild with some of the attributes of "obj", to receive a Testcomplete object, which works, but it takes around 10 seconds for every control, which is not acceptable.
Any better possibility?
Thanks a lot!
Robert
Hi Robert,
> is there any possibility to tell Testcomplete, that "obj" is a WPFButton
No, this is not possible.
If I got it right, .GetControl() is a method of the tested application that returns native .Net object. WPFButton (and others a-like) is TestComplete's wrapper over the .Net object identified via the means provided by TestComplete.
10 seconds for every control seems weird and my guess is that you should optimize either your NameMapping/Aliases or the way how .FindChild is used. (For example, the search that starts at application level and searches for the object that is too deep in the wide objects tree might be slow. But the preliminary search for one or several intermediate parent containers for the same object might speed up the search quite significantly.)