IDataErrorInfo 与 IValidatableObject?
目前我的业务对象实现了IDataErrorInfo
。由于我打算在 ASP.NET MVC 3 中使用这些库,因此我认为我也应该实现 IValidatableObject ,或者也可以代替。
WPF 是否可以与 IValidatableObject
一起使用?
数据注释如何融入图片?
Currently my business objects implement IDataErrorInfo
. Since I intend to use these libraries in ASP.NET MVC 3, I figure I should implement IValidatableObject
as well or maybe instead of.
Does WPF work with IValidatableObject
?
How do DataAnnotations fit into the picture?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
IValidatableObject
是一个用于验证整个对象级别错误的接口。您有责任通过验证数据注释或其他技术来实现它。 MVC 对数据注释具有本机支持,因此您可以直接使用它们而无需任何进一步的支持。相反,wpf 仅支持
IDataErrorInfo
。它不支持IValidateObject
或 DataAnnotations。不过,我实现了一个包装对象,它将 Wpf 中的 DataAnnotation 支持添加到包装对象中。它还提供了 IPropertyChanged 的实现。请参阅 codeplex 上的Wpf 和 Silverlight 验证工具包
IValidatableObject
is an interface for verifying whole object level errors. It is your responsibility to implemts it by verifying data annotations or other techniques. MVC has native support for data annotations so you can just use them without any further support.On the contrary wpf ONLY SUPPORTS
IDataErrorInfo
. It has no support forIValidateObject
or DataAnnotations.However I implemented a wrapper object that add DataAnnotation support in Wpf to the wrapped object. It furnishes also an implementation of
IPropertyChanged
. See the Validation Toolkit for Wpf and Silverlight on codeplex我正在实体上实现
IValidatableObject
,并在 WPF 的视图模型中用IDataErrorInfo
包装它(自动通过基类)。我的实体将在 WPF、MVC 和新的 EF CTP5 中运行良好,它们也支持IValidatableObject
。I am implementing
IValidatableObject
at entity, wrapping it withIDataErrorInfo
at view model (automatically via base class) for WPF. My entities will work well in either WPF, MVC and new EF CTP5 who also honorsIValidatableObject
.