c# - 如何通过 IDataErrorInfo 在按下保存按钮时验证我的实体?

标签 c# silverlight idataerrorinfo

我已经实现了 IDataErrorInfo 接口(interface)来验证我的实体。

<TextBox Text="{Binding User.Name, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}" />

它工作正常,但我想在用户按下保存按钮时重新验证数据。他们是否有任何方法可以在 IDataErrorInfo 中实现此功能。

最佳答案

也许您应该考虑使用 INotifyDataErrorInfo 接口(interface)

这应该给你更多的控制...包括 GetErrors 方法和更多你可以在按钮单击命令上执行的方法(我假设你正在使用 MVVM)

在这里查找信息:

http://msdn.microsoft.com/en-us/library/system.componentmodel.inotifydataerrorinfo(v=vs.95).aspx

这里还有一篇很好的博客文章:

http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2009/11/18/silverlight-4-rough-notes-binding-with-inotifydataerrorinfo.aspx

关于c# - 如何通过 IDataErrorInfo 在按下保存按钮时验证我的实体?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9413441/

相关文章:

c# - BackgroundTask UWP Windows 10 TimeTriggeredTask 示例已注册但从未启动

silverlight - 从 DataTemplate 中绑定(bind)?

c# - 在调试和发布设置 visual studio 中运行不同的代码

c# - 实现IDataErrorInfo接口(interface)时 `public string this[string columnName]`是什么意思?

c# - 具有复杂类型的 IDataErrorInfo

c# - 为什么我不能更改代码中的音量?

C# 线程安全的 getter 性能差异

c# - 无法分配给属性 'System.Windows.Controls.Primitives.ButtonBase.Click'

c# - 如何为多个 BO 属性定义 IDataErrorInfo 错误属性

c# - GlobalAssemblyInfo.cs 和强命名