3

I'm building my first WPF application and some of the validation techniques are getting me confused the more i google looking for a solution.
My application connects to a web service and pulls data for manipulation.After manipulation the app calls another method for example to send the manipulated data. (for example i pull contactInfo[] by calling getContact() that i show on a ListBox, when a contactInfo object is deleted i call removeContact() webmethods).

Now in various windows i need to validate inputs for the data integrity (for example when i add a new contact by calling addContact()). And correct me if my thinking is wrong, i don't need to Bind my controls, mostly textboxes to a DataModel, let's say contactInfo.

Here are my concerns:
Question 1 : is it possible to validate whithout Binding?
Question 2 during my research i found a nice way here on how all the validations can be triggered from a button click event, i'm wondering if that suits the implementation whithout Databinding?
Question 3 : can any one help me? ^^

thanks for reading

Community
  • 1
  • 1
black sensei
  • 6,528
  • 22
  • 109
  • 188
  • This is probably not of help anymore, but I will post anyway for other people looking for the same answer. The validation can be performed in several ways, but mostly by using validation rules, exceptions or implementing the IDataErrorInfo interface. Q1: If you want to validate without Binding, you need to do it yourself (the framework does not help you in any way). If you use data binding, then you can use any of the three options above. – byteflux Apr 23 '12 at 17:07
  • Validation rules allow you to specify the validation criteria declaratively (inside the XAML)- see http://msdn.microsoft.com/en-us/library/ms753962.aspx for an example – byteflux Apr 23 '12 at 17:12
  • Exceptions can be used for validation (although this will give you a hard time when debugging, because the debugger will break by default on every exception). For using exceptions, you need to set the Binding.ValidatesOnErrors property to true. Internally it will add a validation rule which checks for exceptions – byteflux Apr 23 '12 at 17:14
  • The third way to validate is by implementing the IDataErrorInfo interface in your data model, which gives you more granular control over the validation process. – byteflux Apr 23 '12 at 17:16
  • A good starting point for implementing validation is this blog post: http://blogs.msdn.com/b/wpfsdk/archive/2007/10/02/data-validation-in-3-5.aspx – byteflux Apr 23 '12 at 17:17
  • Link in previous comment is no longer valid. The page is archived here: https://web.archive.org/web/20160129054212/http://blogs.msdn.com/b/wpfsdk/archive/2007/10/02/data-validation-in-3-5.aspx – Peter Duniho Apr 20 '20 at 05:41

0 Answers0