在实现 IDataErrorInfo 时,如何在更新后(而不是之前)验证 clr 属性?
我已经在我的一个类中实现了 IDataErrorInfo 来验证该类的属性。该属性绑定到我的 wpf 用户控件上的控件。验证工作正常,但存在一个重大缺陷。
它似乎在更新属性之前调用 IDataErrorInfo 成员 public string this[string columnName] ,因此当我检查正在更改的属性的值时,它包含前一个值而不是刚刚输入的值。因此,验证总是落后一步。这意味着我无法检查刚刚输入的错误值。
有没有什么方法可以强制在更新属性之后而不是之前调用此验证。我尝试将 UpdateSourceTrigger 更改为 LostFocus 和 PropertyChanged,但它们仍然报告以前的值,只是在不同的时间。
谢谢。
I have implemented IDataErrorInfo in one of my classes to validate a property of that class. The property is bound to a control on my wpf user control. The validataion works fine, except there is one vital flaw.
It seems to be calling the IDataErrorInfo member public string this[string columnName] before the property is updated, so when I check the value of the property being changed it contains the previous value not the one just entered. Therefore, the validation is always one step behind. This means that I can't check for incorrect values that have just been entered.
Is there any way of forcing this validation to be called after the property has been updated and not before. I have tried changing the UpdateSourceTrigger to both LostFocus and PropertyChanged but they still report the previous value, just at different times.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在分配属性之前发送属性更改通知时,可以重现您所指的行为。
在实际设置值后调用更改通知可能会解决问题。郑重声明,我不会这样称呼属性更改通知!
The behavior that you are referring to can be reproduced when property change notifications are sent before the property is assigned.
May be calling the change notification after you have actually set the value may do the trick. And just for the record I don't call property changed notification like this!