WPF中的验证(何时使用)

编程入门 行业动态 更新时间:2024-10-26 00:28:21
本文介绍了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!!

推荐答案

您已经在此处! [ ^ ] 答案就在那儿. 我可以在这里提供一个简短的答案: -在需要仅输入整数值的字段中输入字符时,将使用异常处理.它引发的错误消息无法自定义.另外,您不能提供自己的规则,例如年龄应大于1等. -ValidationRule用于通过创建ValidationRule类来实现自己的自定义规则来克服上述两个问题,也可以提供自己的错误消息.这里的问题是,要验证每个控件,您必须创建一个单独的ValidationRule. -IDataErrorInfo可用于克服上述问题.您只需要将IDataErrorInfo接口实现到保存属性的Class. 在我的博客中对此进行了解释: tarundotnet.wordpress/2011/03/03/wpf-tutorial-how-to-use-idataerrorinfo-in-wpf/ [ ^ ] 看看吧,我相信您将能够找到解决问题的方法. 解决方案更新: 以下是一些有用的链接: www.hardcodet/2009/01/combinding-wpf-validation-rules-and-idataerrorinfo-to-validate-conversion-errors [ ^ ] www.codegod.de/webappcodegod/wpf-idataerrorinfo-and-databinding- AID416.aspx [ ^ ] www.codeproject/KB/WPF/Validizor.aspx [ ^ ] 这是另一个简单的实现,但是缺少第一个链接或我的博客中介绍的内容. codeblitz.wordpress/2009/05/08/wpf-validation-made-easy-with-idataerrorinfo/ [ ^ ] 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 : tarundotnet.wordpress/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 : www.hardcodet/2009/01/combinding-wpf-validation-rules-and-idataerrorinfo-to-validate-conversion-errors[^] www.codegod.de/webappcodegod/wpf-idataerrorinfo-and-databinding-AID416.aspx[^] www.codeproject/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.codeblitz.wordpress/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中的验证(何时使用)

本文发布于:2023-11-03 06:30:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1554457.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:WPF

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!