views:

601

answers:

1

In implementing M-V-VM in a project and following advice of Karl Shifflett about implementing a validation framework, but don't really want to use a full framework (like Ocean) only for the validation part.

What validation framework do you recommend that works with the M-V-VM pattern?

+1  A: 

I can only speak from the experience of not using a full validation framework, in as much as I've simply stuck to using what WPF natively offers.

In my project, I implemented the IDataError interface on my entity/data classes, as well as implemented the partial "OnValidate" method that Linq-To-Sql observes, and then as static/shared members of the entity classes, instansiated validation home-brewed helpers which provide the back-end logic for implementing IDataError.Items and OnValidation methods.

Then it's simply a case of adding ValidatesOnErrors=True,ValidatesOnExceptions=True to all of the bindings described in XAML. The end result is encouraging - WPF's ability to provide visual feedback on invalid data is good, and the effort of implementing the validation is minimal.

I'd advise following the trend of keeping user-input validation logic seperate from your property setter logic. Sometimes the validity of one property depends of the state of another property. Keeping the validation logic outside of the property setters allows you to construct apps where the end user is able to input the two values that result in a valid state, without either of the individual property setters rejecting the values as they are being entered in.

Mark
I have a problem, I have a button I want to set its IsEnabled prop according to the validation of the properties in the DataContext, any ideas?
Shimmy