Mathieu Estratat
Top achievements
Rank 1
Mathieu Estratat
asked on 13 Apr 2011, 06:45 PM
Hi,
I need to test the value of a RadNumericUpDown.
When I try to get the property from my element (a ArtOfTest.WebAii.Silverlight.FrameworkElement encapsulating a RadNumericUpDown) using the following code:
I need to test the value of a RadNumericUpDown.
When I try to get the property from my element (a ArtOfTest.WebAii.Silverlight.FrameworkElement encapsulating a RadNumericUpDown) using the following code:
AutomationProperty property = new AutomationProperty(prop, typeof(double?));element.GetProperty(property).ToString(); It does not found the property (I get a Null Pointer Exception). What is wrong and can you help me please? Thanks, Mathieu
5 Answers, 1 is accepted
0
Mathieu Estratat
Top achievements
Rank 1
answered on 15 Apr 2011, 10:14 AM
Hi,
While I was trying to create a sample for this problem I found my error, the second argument of the AutomationProperty should be a string ... - I have fixed my problem by changing the two lines :
In my short sample, I got the following error :
Invalid cast from 'System.String' to 'System.Nullable`1[[System.Double, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]'.
This error is different from my previous Null Pointer exception, but both problems are fixed using typeof(string).
But I do not understand what the second parameter stands for, does anyone has an answer ?
Thx,
Mathieu
While I was trying to create a sample for this problem I found my error, the second argument of the AutomationProperty should be a string ... - I have fixed my problem by changing the two lines :
AutomationProperty property = new AutomationProperty(prop, typeof(double?));by
AutomationProperty property = new AutomationProperty(prop, typeof(string));
In my short sample, I got the following error :
Invalid cast from 'System.String' to 'System.Nullable`1[[System.Double, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]'.
This error is different from my previous Null Pointer exception, but both problems are fixed using typeof(string).
But I do not understand what the second parameter stands for, does anyone has an answer ?
Thx,
Mathieu
0
Hi Mathieu Estratat,
I am glad that you managed to fix the problem.
The second parameter stands for the type of the AutomationProperty you are creating. Without a sample code I can't be really sure why you were getting the errors. I suppose that it is coming from the fact that the type is Nullable. You can try to use not Nullable double.
All the best,
Boyan
the Telerik team
I am glad that you managed to fix the problem.
The second parameter stands for the type of the AutomationProperty you are creating. Without a sample code I can't be really sure why you were getting the errors. I suppose that it is coming from the fact that the type is Nullable. You can try to use not Nullable double.
All the best,
Boyan
the Telerik team
Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Public Issue Tracking
system and vote to affect the priority of the items
0
Hi Mathieu Estratat,
This Type needs to be one of our wrapper classes that match the .NET type as documented in the Silverlight MSDN documentation (unless it is one of the base types such as int, string, etc.). I hope that clarifies for you how to use this function. Kind regards,
Cody
the Telerik team
To expand on Boyan's answer, the second parameter represents what type of .NET object to deserialize/convert the property into. When we read the property from the element it is serialized so that it can be transferred across process boundaries. If we want to get the Foreground color of an element we would write this:
ArtOfTest.WebAii.Silverlight.UI.Brush textblockBrush = (Brush)Pages.TelerikTreeViewFor.SilverlightApp.InstallerTextblock.GetProperty(
new
AutomationProperty(
"Foreground"
,
typeof
(Brush)));
This Type needs to be one of our wrapper classes that match the .NET type as documented in the Silverlight MSDN documentation (unless it is one of the base types such as int, string, etc.). I hope that clarifies for you how to use this function. Kind regards,
Cody
the Telerik team
Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Public Issue Tracking
system and vote to affect the priority of the items
0
Mathieu Estratat
Top achievements
Rank 1
answered on 20 Apr 2011, 09:15 AM
Hi Boyan, Codi,
thanks a lot for your answers.
If I understand well, the second parameter is the Type of the property wrapped in your component except for Type Nullable for which you use the underlying type and the GetProperty returns null by its own if the value is null. Am I right ?
I assume that due to the fact that the two following code run correctly (Assuming a UserControl named QuantitySpinnerExample containing a RadNumericUpDown named QuantitySpinner):
and
while the following one is crashing with the error :
Invalid cast from 'System.String' to 'System.Nullable`1[[System.Double, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]'.
Thanks again,
Kind regards,
Mathieu
thanks a lot for your answers.
If I understand well, the second parameter is the Type of the property wrapped in your component except for Type Nullable for which you use the underlying type and the GetProperty returns null by its own if the value is null. Am I right ?
I assume that due to the fact that the two following code run correctly (Assuming a UserControl named QuantitySpinnerExample containing a RadNumericUpDown named QuantitySpinner):
FrameworkElement elt = Manager.ActiveBrowser.SilverlightApps()[0].FindName(
"QuantitySpinnerSample"
);
elt.Find.ByName<RadNumericUpDown>(
"QuantitySpinner"
).Value = 1000;
AutomationProperty property =
new
AutomationProperty(
"Value"
,
typeof
(
double
));
if
(elt.Find.ByName<RadNumericUpDown>(
"QuantitySpinner"
).GetProperty(property) !=
null
)
Assert.AreEqual(((
double
)(elt.Find.ByName<RadNumericUpDown>(
"QuantitySpinner"
).GetProperty(property))), 1000);
FrameworkElement elt = Manager.ActiveBrowser.SilverlightApps()[0].FindName(
"QuantitySpinnerSample"
);
elt.Find.ByName<RadNumericUpDown>(
"QuantitySpinner"
).Value = 1000;
AutomationProperty property =
new
AutomationProperty(
"Value"
,
typeof
(
string
));
if
(elt.Find.ByName<RadNumericUpDown>(
"QuantitySpinner"
).GetProperty(property) !=
null
)
Assert.AreEqual(((
string
)(elt.Find.ByName<RadNumericUpDown>(
"QuantitySpinner"
).GetProperty(property))),
"1000"
);
while the following one is crashing with the error :
Invalid cast from 'System.String' to 'System.Nullable`1[[System.Double, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]'.
FrameworkElement elt = Manager.ActiveBrowser.SilverlightApps()[0].FindName(
"QuantitySpinnerSample"
);
elt.Find.ByName<RadNumericUpDown>(
"QuantitySpinner"
).Value = 1000;
AutomationProperty property =
new
AutomationProperty(
"Value"
,
typeof
(
double
?));
if
(elt.Find.ByName<RadNumericUpDown>(
"QuantitySpinner"
).GetProperty(property) !=
null
)
Assert.AreEqual(((
double
?)(elt.Find.ByName<RadNumericUpDown>(
"QuantitySpinner"
).GetProperty(property))),
"1000"
);
Thanks again,
Kind regards,
Mathieu
0
Hi Mathieu Estratat,
Cody
the Telerik team
If your code asks for a property that does not exist the framework will throw a ArtOfTest.WebAii.Silverlight.NoSuchPropertyException. You won't get null back from the GetProperty function. So if the property does exist, it cannot have a null value.
Kind regards,Cody
the Telerik team
Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Public Issue Tracking
system and vote to affect the priority of the items