Geeks With Blogs


Add to Google

Tim Hibbard CEO for EnGraph software

Intro to this series of posts.

Some of the code I use for UI validation came from Paul Stovell, who is working on a WPF Element that acts like WinForms 2.0 ErrorProvider control.  Paul's control didn't quite fit my needs, so I've tweaked a few things so I can provide visual validation in a generic fashion from my base class.

All of our objects implement:
Public Event InvalidProperty(string PropertyName, string ErrorMessage);
Public Event Validated(object sender);
Public bool IsValid;

Our objects also implement INotifyPropertyChanged and the validation code is called in OnPropertyChanged.  That way, when the user changes a value, the object is validated and messages are bubbled up to the UI.

In 2.0, it was easy to provide feedback to the user.  Our base UI form had an errorProvider control.  Since all of our forms derived from our base UI and also were bound to an object that implement our base interface, I was able to have a single function in the base UI form that listened for InvalidProperty messages, find the control that was bound to the guilty propertyname and set the errorProvider.  It would also listen to the Validated event and call errorProvider.Clear().  And all was right in the world.

Then we decided to scrap our 2.0 forms and jump into 3.0.  I soon found out that WPF did not have a control comparable to ErrorProvider.  I also found out that it was much more painful to query existing binding paths on a form.

With help from Paul and Google, this is my code-based implementation for UI validation:

This got too long so the rest of the post and all the code is in this article.

Invalid control:



Posted on Thursday, July 19, 2007 11:39 AM .NET , Goldstar , WPF | Back to top

Comments on this post: Real world desktop WPF applications - UI Validation

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Tim Hibbard | Powered by: