嵌套财产和INotifyDataErrorInfo正确的属性名 [英] Correct property name for nested property and INotifyDataErrorInfo

查看:182
本文介绍了嵌套财产和INotifyDataErrorInfo正确的属性名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用WPF中异步验证INotifyDataError接口。我有一个属性。

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

和上SOMETYPE我有属性的类型

and on the type SomeType I have the property

public string Name

现在我的ViewModel实现INotifyPropertyChanged和INotifyDataError和验证我的ViewModel类异步完成。 SOMETYPE仅实现INotifyPropertyChanged。

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

我的问题是这样的。当我提出与 DataErrorsChangedEventArgs(propertyName的)) ErrorsChanged 事件又该propertyName的是。请注意我的绑定的路径是 XXX.Name 。如果propertyName的是

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

  • 名称

或别的东西,或者我要在我的 SOMETYPE 类来实现INotifyDataErrorInfo以及我希望不要有做,因为我希望我的验证,以留在主视图模式。

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.

推荐答案

据我所知,我会说,你必须实现IDataErrorInfo的在您的SOMETYPE类你的财产XXX,因为你绑定到它。我这样做在我的项目和它的作品。

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.

这篇关于嵌套财产和INotifyDataErrorInfo正确的属性名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆