This is a migrated thread and some comments may be shown as answers.

Casting to specific controls fails using Find.ByName().As<Type>()

3 Answers 163 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Jess
Top achievements
Rank 1
Jess asked on 09 Feb 2012, 09:38 PM
I have this line of code in my Test class:

DataGrid grid = app.Find.ByName("cboResident").As<DataGrid>();

I have taken it from this documentation page which indicates I can cast components on a Silverlight page to their "native" types (i.e. DataGrids, ComboBoxes, etc, instead of just returning FrameworkElement, which isn't serving its purpose in this case...) 

Here's the example given in the Telerik documentation:

Grid containerGrid = app.Find.ByText("SomeText").Parent("Grid").As<Grid>();

The problem is that I get a compile time exception that states:

Error: The type 'System.Windows.Forms.DataGrid' cannot be used as a type parameter 'T' in the generic type or method 'ArtOfTest.WebAii.Silverlight.FrameworkElement.As<T>()' There is no implicit reference conversion from 'System.Windows.Forms.DataGrid' to 'ArtOfTest.WebAii.Silverlight.FrameworkElement.'

This is the source of MUCH frustration w/my developers right now and we can't find how to resolve it. We get this compiler error regardless of which type of component we are attempting to cast the FrameworkElement to, whether it be a Silverlight component or something else, even a Telerik component, most frustrating of all.


Any help would be appreciated. 





3 Answers, 1 is accepted

Sort by
0
Accepted
Anthony
Telerik team
answered on 11 Feb 2012, 12:48 AM
Hello Jess,

It appears you have a reference and a using statement for System.Windows.Forms which is causing a conflict.

You can either comment out that using statement if it's not needed, or explicitly refer to the DataGrid like this:

ArtOfTest.WebAii.Silverlight.UI.DataGrid grid = app.Find.ByName("dataGrid").As<ArtOfTest.WebAii.Silverlight.UI.DataGrid>();


Greetings,

Anthony
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Jess
Top achievements
Rank 1
answered on 11 Feb 2012, 01:38 AM
Oh, how careless of me. Thanks. I'll fix it first thing Monday morning.

Cheers. 

J
0
Jess
Top achievements
Rank 1
answered on 13 Feb 2012, 03:23 PM
thanks
Tags
General Discussions
Asked by
Jess
Top achievements
Rank 1
Answers by
Anthony
Telerik team
Jess
Top achievements
Rank 1
Share this question
or