WPF中的验证(何时使用) [英] Validations in WPF(Which to use when)

查看:68
本文介绍了WPF中的验证(何时使用)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
谁能告诉我何时在WPF中使用以下验证方法:
1.异常处理
2.ValidationRule类
3.IDataErrorInfo接口

请提供每个站点都有演示的好站点.谢谢!

Hi All,
Can anybody tell me when to use which validation method in WPF out of following:
1.Exception handling
2.ValidationRule class
3.IDataErrorInfo interface

Please provide any good sites having demo of each..Thanks!!

推荐答案

您已经在 http://tarundotnet.wordpress.com/2011/03/03/wpf-tutorial-how-to-use-idataerrorinfo-in-wpf/ [ http://www.hardcodet.net/2009/01/combinding-wpf-validation-rules-and-idataerrorinfo-to-validate-conversion-errors [ http://www.codegod.de/webappcodegod/wpf-idataerrorinfo-and-databinding- AID416.aspx [ ^ ]

http://www.codeproject.com/KB/WPF/Validizor.aspx [ ^ ]

这是另一个简单的实现,但是缺少第一个链接或我的博客中介绍的内容.
You have already posted the same question before here![^]

And the answer lies there itself.

I can provide a brief answer here :

- Exception handling is used when you enter characters in the field which requires you to input only integer values. The error message it throws cannot be made custom. Also you cannot provide your own rule like age should be greater than 1 etc.

- ValidationRule is used to overcome the above two issues by creating a ValidationRule class to implement your own custom rule, also you can provide your own error message. The problem here is that for validating each control, you have to create a separate ValidationRule.

-IDataErrorInfo can be used to overcome the above issue. You just have to implement the IDataErrorInfo interface to the Class which holds the properties.

This is explained in my blog here : http://tarundotnet.wordpress.com/2011/03/03/wpf-tutorial-how-to-use-idataerrorinfo-in-wpf/[^]

Do have a look and i am sure you will be able to figure out yourself the solution for the problem.

Solution Updated :
Here are a few helpful links :

http://www.hardcodet.net/2009/01/combinding-wpf-validation-rules-and-idataerrorinfo-to-validate-conversion-errors[^]

http://www.codegod.de/webappcodegod/wpf-idataerrorinfo-and-databinding-AID416.aspx[^]

http://www.codeproject.com/KB/WPF/Validizor.aspx[^]

Here is another simple implementation but lacks a thing which is covered and well explained at the first link or in my blog.http://codeblitz.wordpress.com/2009/05/08/wpf-validation-made-easy-with-idataerrorinfo/[^]


Exception 何时生效?您如何从发生异常的情况中恢复过来?
Since when is Exception is validation? How are you going to recover from the situation that arose the exception?


这篇关于WPF中的验证(何时使用)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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