IDataErrorInfo/WPF Binding - Validation over many ViewModels?

"YOU AND THE ART OF ONLINE DATING" is the only product on the market that will take you step-by-step through the process of online dating, provide you with the resources to help ensure success. Get it now!

For validation that is based on business rules, I usually expose a Validation Delegate that my ViewModel can set.

For validation that is based on business rules, I usually expose a Validation Delegate that my ViewModel can set. For example, the ViewModel containing your collection might look like this: public ParentViewModel() { foreach(var user in UserCollection) user. AddValidationErrorDelegate(ValidateUser); } private string ValidateUser(object sender, string propertyName) { if (propertyName == "Email") { var user = (UserVM)sender; if (UserCollection.

Count(p => p. Email== user. Email) > 1) return "Another user already has this Email Address"; } return null; } The idea is that your Model should only contain raw data, therefore it should only validate raw data.

This can include validating things like maximum lengths, required fields, and allowed characters. Business Logic, which includes business rules, should be validated in the ViewModel, and this allows that to happen. The actual implementation of my IDataErrorInfo on the UserVM class would look like this: #region IDataErrorInfo & Validation Members /// /// List of Property Names that should be validated /// protected List ValidatedProperties = new List(); #region Validation Delegate public delegate string ValidationErrorDelegate(object sender, string propertyName); private List _validationDelegates = new List(); public void AddValidationErrorDelegate(ValidationErrorDelegate func) { _validationDelegates.

Add(func); } #endregion // Validation Delegate #region IDataErrorInfo for binding errors string IDataErrorInfo. Error { get { return null; } } string IDataErrorInfo. Thisstring propertyName { get { return this.

GetValidationError(propertyName); } } public string GetValidationError(string propertyName) { // If user specified properties to validate, check to see if this one exists in the list if (ValidatedProperties. IndexOf(propertyName) 0) { foreach (ValidationErrorDelegate func in _validationDelegates) { s = func(this, propertyName); if (s! = null) { return s; } } } return s; } #endregion // IDataErrorInfo for binding errors #region IsValid Property public bool IsValid { get { return (GetValidationError() == null); } } public string GetValidationError() { string error = null; if (ValidatedProperties!

= null) { foreach (string s in ValidatedProperties) { error = GetValidationError(s); if (error! = null) { return error; } } } return error; } #endregion // IsValid Property #endregion // IDataErrorInfo & Validation Members.

I like the approach that @Rachel took here. I've been using the IDataErrorInfo. This to expose range errors from the model, but only after the user clicks OK do I run a business rule check.It's nice being able to use an approach like this to expose the business rule errors to the UI before the user goes through the effort of filling out the rest of the form and clicking OK.

– Kendrick Nov 16 at 18:34 That's exactly what I was looking for! A very good and also simple way to perform "higher-level" checks via IDataErrorInfo while filling out the form. :) – user978052 Nov 16 at 19:29.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions