Validation Attributes Block Updates from Target to Source Property in Data Bindings

Topics: Validation Application Block
Jun 18, 2012 at 3:34 PM

Hi everyone,

I'm using validation attributes from Validation Application Block (VAB) on my view model in an WPF MVVM application.

I found out that when invalid data is input into a WPF control on a window, which is data bound to a property on the view model, the validation will fail, but the data-bound property value is not updated with the new (invalid) value. Because of this, the view model cannot raise the ICommand.CanExecuteChanged event to disable command buttons on the window.

Any advice for this problem is highly appreciated. Thank you.

Jun 19, 2012 at 4:51 AM

I found the solution here: http://stackoverflow.com/questions/5894449/validation-application-block-5-and-wpf-view-model

It seems that the Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WPF.Validate class blocks the property updating from target to source when data is invalid. The work around is not to use the attached property from VAB WPF integration lib., implement IDataErrorInfo on view model, and set ValidatesOnDataErrors=True on binding expressions.

Hope this helps others.