6

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

  • XXX.Name
  • Name

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.

4

1 回答 1

3

afaik 我会说你必须在 SomeType 类中为你的属性 XXX 实现 IDataErrorInfo 因为你绑定到它。我在我的项目中这样做并且它有效。

于 2013-10-16T11:26:15.517 回答