Click here to Skip to main content
15,900,906 members
Please Sign up or sign in to vote.
1.50/5 (4 votes)
See more:
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!!
Posted
Updated 15-Mar-11 4:46am
v3

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/[^]
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 15-Mar-11 21:32pm    
Hey, you made a fine tool to give Answers! My 5.
Are there other purposes of your site? :-)
--SA
Tarun.K.S 16-Mar-11 2:08am    
Hahahaha! Thats true. :) Well through this blog, i can impress my boss and also my next employer! :D
Sergey Alexandrovich Kryukov 16-Mar-11 3:15am    
Good luck :-)
Vishal Misal 16-Mar-11 4:21am    
Thnx Tarun..helpful answer..
bt i cant access ur blog frm company..:(
Tarun.K.S 16-Mar-11 4:25am    
No problem, you can do this at home. It's not tough either. Good luck and do mark it as answer.
Since when is Exception is validation? How are you going to recover from the situation that arose the exception?
 
Share this answer
 
Comments
Vishal Misal 15-Mar-11 9:20am    
i ddn't mean exception as validation.
We can use exception hanlind to handle errors,thts wht i meant..
Sergey Alexandrovich Kryukov 15-Mar-11 21:29pm    
Also, exceptions are not generally errors, did you know that? (Surprise!)
--SA
Sergey Alexandrovich Kryukov 15-Mar-11 21:30pm    
Yes, one can recover, but this topic is pretty far from validation.
My 5 for the rant along... :-)
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900