tags:

views:

35

answers:

1

What technique or library do you recommend for on-screen validation. That is, validation that is very visible to the user.

My requirements:

  1. The validation must have a way to indicate to the user which fields have a problem.
  2. The validation must have a way to indicate to the user how to fix the problem.
  3. The validation must support comparatives like TextboxA > Textbox B.
  4. The validation must support custom logic like "If CheckBoxC is checked, ListBoxD must be empty".
  5. Sometimes, though not always, the user can save a record even though validation fails.
+2  A: 

A combination of using IDataErrorInfo and ValidationRules should meet all of your criteria.

1 & 2 - can be handled easily using the standard WPF validation display techniques. For background info, I'd read Josh Smith's MSDN article, in particular, he shows a couple of ways to handle displaying validation information.

3 & 4 - can be handled easily via IDataErrorInfo. This interface lets you do any logic required in order to display validation, and can combine multiple properties in the validation rules.

5 - This is a matter of just tracking which rules prevent saving, and which do not. You'll need to handle this directly, but again, IDataErrorInfo can help here, since you can use a known set that allow saving, and have every other issue prevent it.

For simple cases, Validation Rules make life easy. They can be combined with IDataErrorInfo, however, for a nice mix of simple with extended logic for difficult cases.

Reed Copsey
Thanks, that sounds really promising.
Jonathan Allen