Reputation: 1900
I'm coming from a Delphi programing world, I'm starting to learn Silverlight, Entity Framework, RIA Services, MVVM and all that stuff.
I want to know if is there some kind of technic, controls, approach, pattern or something else that allows you to do some simple validations or verifications live in the client when the user is typing. In the Delphi world the controls (DB-Aware ones) have the ability of doing that, they know which is the type of the data they are showing, you can configure the max length, in general they know some information about the data like that a floating point type does not allow more than just one point in it and so on.
I understand is different and that you have to do validations in your business classes, your services, your models, your domain and it depends what you are using, and also in your database.
Any thoughts suggestion that can help with this?
Excuse me my English is not my main language.
Upvotes: 1
Views: 528
Reputation: 34820
Validation in Silverlight is tied closely to binding, and is most commonly done in one of two major ways:
Client-side validators depend on exceptions thrown in the setter when the validation fails. Server-side validation returns notifications when a validator fails. The two binidng options for this are ValidatesOnExceptions
(client-side) and NotifyOnValidationError
(server-side.)
It sounds like you're wanting "real-time" validation as you type. The most practical application for this would be formatting validation, such as for email addresses or Social Security numbers. This is typically done with regular expression validators.
The short story is no, there is nothing "out of the box" for this type of validation, but it can be done. Validation is applied at the property level using DataAnnotations:
http://msdn.microsoft.com/en-us/library/dd901590(v=vs.95).aspx
You can use the RegularExpressionAttribute to validate a text property against a regular expression. However, under normal conditions your value will only be validated after update, meaning only when you tab away from the control being validated. You can use the UpdateSourceTrigger=Explicit
binding option to validate as you type:
Here is a good overview of data validation in Silverlight:
http://www.devproconnections.com/article/silverlight-development/Silverlight-Data-Validation.aspx
Upvotes: 1