IDataErrorInfo.Error有什么用处? [英] What is IDataErrorInfo.Error good for?

查看:146
本文介绍了IDataErrorInfo.Error有什么用处?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果首先使用IDataErrorInfo,则必须实现它,但是它有什么用呢?我看到的所有示例都只是返回null而不是以某种方式使用此属性.

you have to implement it, if you use IDataErrorInfo in the first place, but what is it good for? all the examples i saw just returned null instead of using this property somehow.

推荐答案

看看文章: ^ ].它解释了IDataErrorInfo的良好用法.
Take a look at article : Delegates and Business Objects[^]. It explains a good use of IDataErrorInfo.


我查看了文章并下载了项目
这是他的用途:

i looked in the article and downloaded the project
here is what he uses:

public virtual string Error {
    get {
        string result = this[string.Empty];
        if (result != null && result.Trim().Length == 0) {
            result = null;
        }
        return result;
    }
}



问题是,我不知道"this []"是什么.它不是数组吗? :confused:
但是无论如何..再次只有null返回.
那么这个错误字符串怎么了?仍然没有得到它



the thing is, i dont know what "this[]" is. its not an array right ? :confused:
but anyway .. again only null returns.
so whats the matter with this Error string? still dont get it


IDataErrorInfo是用于处理模型(数据)与模型所绑定的用户界面之间的验证的接口.它是在模型上实现的.

样本中的"this"是指"Error"方法所属的对象(类的实例).它必须是具有默认属性的类的一部分.如果不查看整个类,该代码片段将毫无意义.

WPF(Windows Presentation Foundation)为您提供了一些非常强大的方法来向用户显示错误.我建议您看一个更完整的示例,例如:

WPF业务应用程序系列第2部分,共n部分-绑定到IDataErrorInfo.Error属性的表单通知控件

希望对您有所帮助.
IDataErrorInfo is an interface for handling validation between the model (data) and the user interface that the model is bound to. It is implemented on the model.

The "this" in your sample refers to the object (instance of the class) in which the "Error" method belongs. It must be part of a class that has a default property. That code fragment is meaningless without looking at the entire class.

WPF (Windows Presentation Foundation) gives you some very powerful ways to present errors to your user. I would recommend that you look at a more complete example such as:

WPF Business Application Series Part 2 of n - Form Notification Control That Binds To IDataErrorInfo.Error Property

I hope this helps.


这篇关于IDataErrorInfo.Error有什么用处?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆