问题标签 [inotifydataerrorinfo]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
3633 浏览

wpf - 如何正确实现 INotifyDataErrorInfo?

我对MSDN 示例有点困惑。

目前尚不清楚如何处理和设置实体相关的错误。

示例中的代码:

但 GetErrors() 的文档指出:

propertyName - 要检索验证错误的属性的名称;或 null 或 Empty,以检索实体级错误

另一个例子建议只返回字典的 _errors.Values 。这只是所有属性错误,但又不是实体错误。

0 投票
1 回答
1128 浏览

wpf - 如何使用 INotifyDataErrorInfo 在 WPF 4.5 中显示与实体相关的错误?

MSDN 文档指出,GetErrors如果 propertyName 为 null 或为空,则该方法应返回与实体相关的错误。

但调试表明 propertyName 始终是正在验证的属性的名称。

我应该怎么做才能强制 WPF 询问与实体相关的错误?

更新

看起来这在ValidationSummary存在控制的 Silverlight 中是可能的。

0 投票
1 回答
170 浏览

c# - 使用反射获取所有属性并在方法中传递每个属性

我正在使用 simplemvvmtoolkit 进行验证(INotifyDataErrorInfo)。我不想为视图模型中的每个属性一遍又一遍地重复我自己,我喜欢使用反射来获取所有属性并验证它们,但我似乎无法弄清楚在 validateProperty 方法中传递什么。

ValidateProperty 接受:

0 投票
1 回答
908 浏览

xamarin.android - 如何将 IDataErrorInfo 与 mvvmcross 和 monodroid 一起使用

我正在尝试构建一个跨平台应用程序。目前我正在使用 Xamarin MonoDroid 4.7 和 MVVMCross 建立一个项目。我希望能够使用 INotifyDataErrorInfo 但我收到以下编译错误:

“System.ComponentModel.INotifyDataErrorInfo”类型存在于“c:\Program Files(x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v1.0\System.dll”和“c:\Users\MvvmCross.PortableSupport”中。 3.0.6\lib\MonoAndroid16\System.Windows.dll

有没有人遇到过这个/开发了解决方法或解决方案?

谢谢

0 投票
0 回答
229 浏览

c# - 有没有办法通过 viewmodel 在模型中传播输入验证

我有一个具有一些属性的模型,在该模型中我进行了一些验证检查(检查值是否不超过范围、是否为数字、是否为有效的邮政编码等)。我认为这些检查应该由模型完成。

我可以选择使用以下验证接口之一:INotifyDataErrorInfoIDataErrorInfo. 我没有偏好。

我有一个视图模型,它公开了模型的许多属性以及一些额外的、特定于视图的和管理属性,例如 IsSelected、IsInScope、IsSaved 等。

视图(在本例中是 DevExpress 的 DxGrid)绑定到视图模型的集合,因此它隐藏了模型的验证检查(它绑定到视图模型的接口)。有没有一种简单的方法可以将模型的验证检查传播到视图,并通过视图模型?

编辑:仅供参考,我正在使用 Simple MVVM Toolkit,它已将 INotifyDataErrorInfo 合并到其 Model 基类中,但未合并到其 Viewmodel 基类中。

0 投票
2 回答
1556 浏览

wpf - 绑定到 DbSet 时如何在 WPF 中处理验证。当地的?

DbSet<T>.Local提供了一个ObservableCollection可以绑定到 WPF 控件的控件。就我而言,我将它绑定到网格。

如果我使用视图模型,我会让它们实现INotifyDataErrorInfoor IDataErrorInfo,然后编写 Fluent Validation 验证器来处理验证。

但在这里我通过DbSet<T>.Local. 我应该如何处理验证?

我应该实施INotifyDataErrorInfo还是IDataErrorInfo在我的模型上实施?

或者有其他选择吗?

0 投票
2 回答
2147 浏览

c# - INotifyDataErrorInfo 实体级验证。如何引发 Validation.Error 事件?

我有以下问题:

我正在使用 INotifyDataErrorInfo 验证来验证我的模型。现在我需要在“实体级别”上验证我的模型,因此应该验证模型对象的整个状态。

这一切正常,验证规则返回错误,但我现在如何确保为我的模型引发 Validation.Error 事件,以便我可以在 MainWindow-Level 捕获它以显示错误消息?

对于我的属性,我在 xaml 中编写了以下内容,因此引发了 Validation.Error 事件:

如果有人可以为我提供一个工作示例,我将非常高兴,谢谢!

0 投票
1 回答
1047 浏览

wpf - Correct property name for nested property and INotifyDataErrorInfo

I'm using the INotifyDataError interface for async validation in WPF. I have a property

On my view model I have a property

and on the type SomeType I have the property

now my ViewModel implements INotifyPropertyChanged and INotifyDataError and validation is done asynchronously in my viewmodel class. SomeType only implements INotifyPropertyChanged.

My questions is this. When I raise ErrorsChanged event with DataErrorsChangedEventArgs(propertyName)) what should the propertyName be. Note my Binding path is XXX.Name. Should propertyName be

  • XXX.Name
  • Name

or something else or do I have to implement INotifyDataErrorInfo in my SomeType class as well which I was hoping not to have to do as I want my validation to stay in the main view model.

Anyway I've tried both above and the textbox is not getting a red box around it though I can verify that the error event is being raised.

0 投票
1 回答
2742 浏览

c# - DataGridRow 错误指示器不适用于 INotifyDataErrorInfo

我正在尝试更新我的 ViewModel 以使用 INotifyDataErrorInfo 而不是 IDataErrorInfo 并且遇到以下问题:

当前编辑字段的验证似乎可以正常工作,但直到我结束对出现错误的字段进行编辑,然后开始重新编辑它时,才会出现行级错误指示器。之后,错误指示器消失,修复验证错误后的事件。

换句话说:我第一次编辑行时,TextBox 轮廓正确地变为红色,但行指示器没有出现。重新编辑行会导致行指示器出现。修复验证错误会导致字段轮廓消失,但会留下感叹号。

请注意, IDataErrorInfo 似乎工作正常。这是我遇到问题的 INotifyDataErrorInfo。

解决方案的一半:将绑定更改为 TwoWay 会导致行指示器正确显示,但它仍然不想消失。

这是视图:

这是视图模型:

似乎已经在 SO 上提出了这个问题,但被原作者删除了:https ://stackoverflow.com/questions/18113718/wpf-datagridrow-inotifydataerrorinfo-as-tooltip-buggy?answertab=active 的副本原来的问题,但这里没有答案:http: //bolding-techaswere1.blogspot.com.au/2013/08/wpf-datagridrow-inotifydataerrorinfo-as.html

编辑:

这是我的测试源代码: https ://github.com/dcrowe/WPF-DataGrid-Validation-Issue/tree/master/DataGrid%20Validation%20Issue

这是我提交给 MS 的报告: https ://connect.microsoft.com/VisualStudio/feedback/details/807728/datagridrow-error-indicator-not-working-with-inotifydataerrorinfo

0 投票
2 回答
1278 浏览

c# - using INotifyDataErrorInfo

On my class I am implementing INotifyDataErrorInfo and it is working fine when validation error happens. It is putting that red frame around the TextBox, but it is not getting rid of it when validation error is fixed.

Here is my code:

I am calling RemoveError() method to remove errors. Am I doing something wrong? When validation fixed I need to go to TextBox and tabbing of will take care of it. I want to remove that red frame right away when validation error is gone.

UPDATE:

When I type something to text box I need to send that info to the server asynchronously and response will bring me a message if there is any validation issues. So I can't do validation things on property changed. I will check for response if there any message added or removed. If any removed then I will call CheckValidationErrors().

ANSWER

I was implementing IDataErrorInfo and then decided to implement INotifyDataErrorInfo. I was thinking to make this validation work I need to implement both interfaces. So basically I removed IDataErrorInfo implementation from my class and that fixed the problem.

Thanks for the help!