The problem is, I usually don't have an exact mask that I require. In some case, any integer is valid. In some cases, any positive double is valid, regardless of the number of decimals, etc.
Is maskednumericinput the best control for me? Or should I be using something else? I'd appreciate advice on how to get this working.
--Christina
5 Answers, 1 is accepted
Could you please examine this documentation article and let us know if it could be a good starting point for you?
Kind regards,Petar Mladenov
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
More information:
These controls are in a form that will be used to "Mass Update" several instances of a class to identical values. I can't modify the validation of the class itself (primarily because the class is defined in a .asmx and imported through a service reference -- this allows bindable properties, but the Web Site project doesn't have the silverlight validation objects and events, unless I'm missing something).
My first solution to this was to just allow generic input and then check to make sure that it was an integer, or a double, or whatever else was valid when the user hit Submit, and using a message box to let them know that they needed to fix values. I've gotten feedback that it would be better if the user knew before they hit submit that they've input something invalid or (better yet) that they could only input valid values in the first place.
I'm not worried about format or range, as long as it's a valid double or integer.
I've looked into manual validation (in on lose focus) but couldn't figure out how to do it without binding to a property with validation code, because I can't manually set the ValidationError (stupid internal class...). I was hoping to find some control that would help me.
--Christina
One thing you could do is to create a "wrapper" classes in your client project. They will wrap the classes that comes from the Service and you will be able to make the validation on the client.
On the other hand, if you use WCF RIA Services, you will be able to validate through data annotations as it is described in the last section from the mentioned help article. What is the type of Service that you use ?
Petar Mladenov
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
For example, my "FileNode" class has a property: Int32? VerticalResolution.
I've created a new class in my Silverlight project like this:
public
class
ValidatingFileNode: FileNode {
public
String ValidVerticalResolution
{
get
{
return
VerticalResolution.ToString(); }
set
{
if
(String.IsNullOrEmpty(value))
{
VerticalResolution =
null
;
return
;
}
Int32 iVal;
if
(!Int32.TryParse(value,
out
iVal))
{
throw
new
Exception(
"Value must be an integer."
);
}
if
(iVal<0)
{
throw
new
Exception(
"Value must be positive."
);
}
VerticalResolution = iVal;
}
}
}
Then, I bind my form grid to a ValidatingFileNode StaticResource, and use a normal TextBox bound to my new ValidVerticalResolution property:
<
TextBox
x:Name
=
"numVert"
Width
=
"108"
Height
=
"20"
Text
=
"{Binding ValidVerticalResolution, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnExceptions=True}"
/>
I'm getting the validation errors popping up correctly. And once I'm done I'll be able to use my custom localization manager to properly localize the error strings.
This idea was very helpful! It never occurred to me as a solution to my problem.
--Christina.
We are glad to hear that the idea helped. Please let us know if you need further assistance. We would be glad to help you.
Best wishes,Petar Mladenov
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>