Correct property name for nested property and INotifyDataErrorInfo

只谈情不闲聊 提交于 2019-12-10 17:06:14

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/19401955/correct-property-name-for-nested-property-and-inotifydataerrorinfo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!