DataForm control error message issue
I am developing a Silverlight web app and got stuck on the current problem.
Is it possible to make a field required only if value is entered into another field. For example if you have a DataForm to save cars. The car model is only required except if you choose a car type from the dropdown list (SUV, Compact, Sports car) you have to also enter the number of doors.
To make it clear:
开发者_如何学CName - required
Engine type - not required
Tyres - not required
Car type - not required
Number of doors - required only if car type is chosen
how can i do that?
Edit: I would like to be able to show the error messages at the bottom as well as highlighting controls that are required
What you need to do called Entity-level validation. Instead of validating 1 property - you need to validate whole object.
To do that - you need to implement INotifyDataErrorInfo. Than on your backing object you will need to handle property setter for CarType. When it changes - you would raise error for NumberOfDoors (if it is not set). Same thing, if NumberOfDoors set - you will need to manually clear that error.
Here you can see some good examples on how this is done: http://www.silverlight.net/learn/data-networking/validation/implementing-data-validation-in-silverlight-with-inotifydataerrorinfo
Also, as a side note - you will max out DataForm capabilities very soon if you will need more advanced scenarios.
精彩评论