tags:

views:

28

answers:

3

Hello

in my MVVM application I have a list of element implementing IDataErrorInfo and INotifyPropertyChanged

the view validate the VM objects when a propertychanged event is raised.

the problem is that the validation result depends not only by the internal state of the object but also by the "enviroment" that is the other objects belonging to the list.

So I need that the validation is called on all the elements of the list every time that an object is deleted or updated.

How can i force the validaiton in this way?

+1  A: 

within the VM which holds the list, each time your list changes, iterate over the list and tell each object to raise property change notification either on the properties you know might be invalid or just every property by setting the property name to an empty string.

It sounds like your validation may be across multiple objects, in which case you need to run your validation from the VM mentioned above and set error messages in the appropriate objects in the collection and then raise the property changed event on those objects.

I have done this previously by having a SetErrorMessage(string string) public method on the objects implementing IDataErrorInfo, and a public OnPropertyChanged(string) method so that I could set errors and raise contextual property changed events from outside the object.

The errors would be stored in a dictionary and the this[string] property would look up the dictionary for errors as well as run its own validation.

benPearce
A: 
Guru Charan
A: 
Guru Charan