winforms中的IDataErrorInfo
IDataError 信息可以在 winforms 应用程序中正确使用吗?过去,我以通常的方式进行绑定(1),并在特定控件的 OnValidating 事件中进行验证。我想将数据验证移至域模型,以便我可以轻松地更换用户界面,并使所有逻辑都位于一处。
我正在研究 IDataErrorInfo,但我发现的所有内容都与 WPF 相关,并且正在开发的应用程序严格来说是一个 winforms 应用程序。
我还注意到 WPF 中使用的绑定位于 System.Windows.Data 中,而我一直使用的绑定位于 System.Windows.Forms 中(当我尝试添加它时,我似乎没有该绑定)作为资源 - 我正在使用 3.5)。除了属性“ValidatesOnDataErrors”之外,两者之间还有区别吗?
(1)通常的做法是:
myControl.DataBindings.Add(new Binding("Text", this.domainModel, "Property"));
Can IDataError info be used properly in a winforms application? In the past I was doing my binding the usual way(1) and did the validation in the OnValidating event of the particular control. I would like to move the data validation to the domain model so that I can easily swap out user interfaces and so that all of the logic is in one place.
I was looking into IDataErrorInfo but everything I find deals with WPF and the app in development is strictly a winforms app.
I also noticed that the binding that gets used in WPF is in System.Windows.Data and the binding that I've always been using is in System.Windows.Forms (which I don't appear to have when I try to add it as a resource - I'm using 3.5).Aside from the property "ValidatesOnDataErrors" is there a difference between the two?
(1) the usual way being:
myControl.DataBindings.Add(new Binding("Text", this.domainModel, "Property"));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这适用于 Windows 中的 ErrorProvider 组件表格。
有关完整但非常简单和简短的教程,请参阅 这篇博文。
This works with the ErrorProvider component in Windows Forms.
For a complete, but very simple and short tutorial, see this blog post.
是的,
IDataErrorInfo
在 winforms 中工作。例如,DataGridView
将在每行和每单元格中自动使用此功能。但它是特定于实现的,并且不会自动应用于其他绑定。我曾经编写过一些代码将其关联到错误提供者并通过更改事件完成工作,但不幸的是我没有它。但我记得好像并不大。Yes,
IDataErrorInfo
works in winforms. For example,DataGridView
will use this automatically both per-row and per-cell. But it is implementation-specific, and isn't automatically applied to other bindings. I did once write some code to associate it to an error-provider and do the work via change events, but I don't have it to hand unfortunately. But I seem to recall it wasn't huge.