Validating data in wpf

I’m not going to harp too much on the details presented in these other articles.

Instead, I’m going to layout what I did to get this working and hopefully give you enough information to get started.

For this example, we need a validation rule that will report when the user attempts to insert a non-integer character.

We also want to be able to specify a range of acceptable values.

Consuming Custom Validation Rules Now that we have an class, let’s add it to our XAML so we can put it into action.I mentioned previously that checks the validation after the property has been updated.This means if we attempt to insert a non-integer field with a non-integer value, the validity checking never occurs: instead, WPF swallows the error.This handy little approach finally gave us a nice way to alert the user of the problem without being too heavy handed in the UI. First of all, it took a lot of code behind to manage the Error Provider: checking field values against business rules, updating the provider’s list of errors, or clearing it out when the status was OK ended up being a lot of code, especially when there were a lot of data fields.And then, beyond deciding whether or not the Error symbol would blink (I always the blinking exclamation point), there wasn’t a lot of pizzazz we could add. Getting Started Before I go any further, you can find most of the basics in these articles: I recommend reading these articles.

Leave a Reply