ValidationSummary 显示非表单验证
我正在编写一个 Silverlight 屏幕,它从文件中获取用户输入,解析文件并将所有验证错误显示在屏幕上。文件中的数据永远不会显示,屏幕的目的纯粹是为了验证反馈。
我决定创建一个实现 INotifyDataErrorInfo 的 ViewModel,在我看来,我将使用 ValidationSummary 控件来显示这些错误。
我这样做的想法是,ValidationSummary 控件将侦听 ViewModel 上的 INotifyDataErrorInfo.ErrorsChanged 事件,并随着 ViewModel 状态的变化相应地更新自身。
不幸的是它不起作用。
如果我将 TextBox 添加到视图并将其绑定到 ViewModel 上的属性...由于更改 TextBox 中的值而发生的任何验证错误都会出现在摘要中 - 这很好地确认了我已正确实现 INotifyDataErrorInfo 。
ValidationSummary 控件是否真的依赖于 UI 交互/绑定来显示错误?
无论 UI 如何组成,它都应该侦听来自 INotifyDataErrorInfo 的任何消息的假设是否正确?
预先感谢您的帮助。
I am writing a Silverlight screen that takes user input from a file, parses the file and displays any validation errors onto the screen. The data from the file is never displayed, the purpose of the screen is purely for validation feedback.
I decided to create a ViewModel that implements INotifyDataErrorInfo and in my view I would use the ValidationSummary control to display those errors.
My thinking in doing this was that the ValidationSummary control would listen to the INotifyDataErrorInfo.ErrorsChanged event on my ViewModel and would update itself accordingly as the state of the ViewModel changes.
Unfortunately it isn't working.
If I add a TextBox to my View and bind it to a property on my ViewModel... any validation errors that occur as a result of changing the value in the TextBox do appear in the summary - which confirms nicely that I have implemented INotifyDataErrorInfo correctly.
Does the ValidationSummary control really depend on UI interaction/Binding for it to display errors?
Is the assumption that it should listen to any messages from INotifyDataErrorInfo regardless of how the UI is composed correct?
Thanks in advance for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
ValidationSummary 控件需要与正在验证的控件位于同一容器中才能显示错误。我没有成功显示实体级验证,也没有找到有关此主题的太多信息。
据我了解 - 您需要创建自己的验证摘要控件来侦听事件并绑定到错误源。
ValidationSummary control needs to be in a same container as controls that being validated in order to display errors. I didn't succeed at displaying entity-level validations and didn't find much information on this topic.
As I understand - you need to create your own validation summary control that listens to event and binds to error source.
我认为出于此类原因使用
INotifyDataErrorInfo
的目的是不正确的。 MSDN 是这么说的:和现在的问题是:我们需要实现这个接口吗?
我认为,为了通知用户导入或导出数据的结果,使用 MVVM 模式和 INotifyPropertyChanged 就足够了。
I think the purpose of using
INotifyDataErrorInfo
for such reasons is incorrect. Here what MSDN say:And now the question is: do we need to implement this interface?
I assume that for informing user about result of importing or exporting data, using MVVM pattern and
INotifyPropertyChanged
will be more than enough.