I've one binding that looks like:
<MyControl SomeProperty="{Binding VmProperty.SubProperty.SubSubProperty.Name, ValidatesOnDataErrors=True}" />
Every class on the way implements IDataErrorInfo, but currently, only my last class has a real check for the name:
public string this[string propertyName]
{
get
{
if (propertyName == nameof(Name))
{
if(someCheck){
return "oh oh";
}
}
return string.Empty;
}
}
public string Error{
get{
return this[nameof(Name)];
}
}
Now I'm changing the value to something incorrect, what I get:
- The
this[string propertyName]on my last last submodel is called properly and returns an error - The
this[string propertyName]on my view model isn't called(neither are all other level) - The control doesn't display the red square around it(it does if I bind directly to a local property of my VM.
So my understanding is that:
IDataErrorInfoerrors are not bubbled up to the Binding- My
IDataErrorInfoimplementation of the view model is not called because it doesn't know that a sub-sub-sub-sub-property has been updated.
How should can you handle this? Either a way to be informed when a sub-sub-sub-sub-property is changed(any of the level could be changed, so I registering to every PropertyChanged event of every level would be really cumbersome), either bubble up errors?
Correct.
Correct.
Your child view model needs to notify the parent view model that it has had its state changed and the parent view model needs to handle this event.
In .NET Framework 4.5 and later, there is a new
INotifyDataErrorInfointerface that declares anErrorsChangedevent that you can use for this. Here is an example of how to implement it.