I've got a viewmodel that implements the INotifyDataErrorInfo
interface.
When a property is updated and a validation error occurs, I call the ErrorsChanged
event, the binding engine then knows it has to call the GetErrors(string propertyName)
method on my viewmodel, and from there I return the IEnumerable
of errors for the corresponding propertyName
.
Nothing special.
But when I was debugging, it seems to be that the GetErrors()
method is called when a viewmodel property changes (on invoking INotifyPropertyChanged.PropertyChanged of course). Even while my viewmodel didn't invoke ErrorsChanged
.
Does the binding engine call GetErrors()
on its own when a property change is notified? (And thus not only when my viewmodel explicitly invokes ErrorsChanged
?)
I can't find it in the docs.
Does the binding engine call GetErrors() on its own when a property change is notified? (And thus not only when my viewmodel explicitly invokes ErrorsChanged?)
Yes. The TransferValue
method, which eventually get called when you raise a PropertyChanged
event for a UI bound source property, in the BindingExpression
class calls UpdateNotifyDataErrors
as you can see in the source code.