如何阻止IDataErrorInfo触发新项目? [英] How can I stop IDataErrorInfo from firing for new items?

查看:76
本文介绍了如何阻止IDataErrorInfo触发新项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发WPF应用程序(使用MVVM),并且已经在ViewModel上实现了IDataErrorInfo.我的验证部分检查是否已输入必填字段.这非常适合编辑现有记录,但是在添加新记录时不能提供良好的用户体验.加载新视图后,必填字段会突出显示为无效.

I am developing a WPF application (using MVVM) and have implemented IDataErrorInfo on my ViewModel. Part of my validation checks that mandatory fields have been entered. This works perfectly for editing existing records but doesn't provide a nice user experience when adding new records. As soon as I load the new view, the mandatory fields are highlighted as invalid.

是否有对此(最好是非hacky)的解决方案?似乎是很标准的事情,所以我希望我缺少一些简单的东西.

Is there a (preferably non-hacky) solution to this? It seems a pretty standard thing to want, so I'm hoping I'm missing something simple.

推荐答案

使用指示记录是否为新的标志.在IDataErrorInfo的实现中选中此标志,并在用户第一次尝试验证输入时将该标志设置为true.

Use a flag that indicates whether the record is new. Check this flag in your implementation of IDataErrorInfo, and set the flag to true the first time the user tries to validate the input.

这篇关于如何阻止IDataErrorInfo触发新项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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