Silverlight supports data validation in TwoWay bindings for target-to-source updates. To setting the following two properties ValidatesOnExceptions=True,NotifyOnValidationError=True to True we can receive Error Notification from Binding engine.
Note: Siliverlight throws Exception in two cases
- Exceptions thrown from the binding engine's type converter.
- Exceptions thrown from the binding object's set accessor.
Setting ValidatesOnExceptions to true tells the binding engine to create a validation error when an exception occurs.
Setting NotifyOnValidationError to true tells the binding engine to raise the BindingValidationError event when a validation error occurs and resolves.
The BindingValidationError event is a routed event, so if you do not handle it on the element that raised the event, it will continue to bubble up until it is handled.
Here is sample Program. Here i going to build a small data entry form which requires user to enter Name , Age, Email and Phone. in this Data entry form I am setting Name,Email, age are Required fields and Age is numeric if you enter more than 100 it will throw an Expectation saying Invalid Input. No validation set on Phone Property . all the above mentioned properties makes a class called Contacts as shown below.
Now i am Initializing the Contacts class properties with the following values as shown.
All Inputs field has valid data.
This form shows Name can not be empty.
This Data entry form shows Age can not be more than 100 .