Showing posts with label validation. Show all posts
Showing posts with label validation. Show all posts

Sunday, October 4, 2009

What's with WPF Data Validation?

Why did I have to spend so long at work last week replicating Silverlight's input validation template behaviour in WPF? Surely I'd have been able to find this work done by someone else? Maybe they're like me and can't really post what they've done for public use.

Don't see how you can write a decent WPF LOB application though without creating some half decent input validation templates.... They must be out there somewhere. Maybe my google skills aren't as good as I thought....

Thoughts on John Papa's DataForm MSDN Article

A nice article on using the DataForm. Documentation is lacking for this control, and most blog posts are out of date, as last minute changes were made before it was released.

Is it good to use the CustomValidator attribute? Stuff I've done recently is not using attributes. It means the validation checks are in the property setters.... Is this good? It keeps things contained, but maybe the validation doesn't really belong there.....

It is using databinding directly to the Employee model. Properties such as Age are integers, so if a character is entered, the model retains the old value and appears internally to be valid, even though the view is now in an invalid state, which is bad. Also, it means the only error message you can give the user is "Input string is not in a valid format". I think it's better to have a ViewModel, bind only to it, and have properties such as Age defined as a string so that any value can be set, and then checked for validity. Means the View and the ViewModel are kept in sync, and you can give the user customised error messages.

I'd hate to see the look on our UCD guys' faces if I had to tell them I couldn't give them a custom error message if an alpha was typed into a numeric field... Probably get more of that "that's crap, it's easy to do in Flex...." ;-)