wpfvalidationbindinginotifydataerrorinfo

Correct property name for nested property and INotifyDataErrorInfo


I'm using the INotifyDataError interface for async validation in WPF. I have a property

<TextBox Grid.Column="5" 
         Text="{Binding XXX.Name, ValidatesOnNotifyDataErrors=True}"/>

On my view model I have a property

public SomeType XXX

and on the type SomeType I have the property

public string Name

now my ViewModel implements INotifyPropertyChanged and INotifyDataError and validation is done asynchronously in my viewmodel class. SomeType only implements INotifyPropertyChanged.

My questions is this. When I raise ErrorsChanged event with DataErrorsChangedEventArgs(propertyName)) what should the propertyName be. Note my Binding path is XXX.Name. Should propertyName be

or something else or do I have to implement INotifyDataErrorInfo in my SomeType class as well which I was hoping not to have to do as I want my validation to stay in the main view model.

Anyway I've tried both above and the textbox is not getting a red box around it though I can verify that the error event is being raised.


Solution

  • afaik i would say you have to implement IDataErrorInfo for your property XXX in your SomeType class because you bind to it. i do this in my projects and it works.