Wpf textbox error validating
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.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.This will create an instance of the custom validation rule with the specified property values.
In this case we are allowing the integer range to be between 999, and specifying the name we want the message to associate with any error.
Using a validation rule causes the validation to occur before the property is updated, so we can easily prevent such an occurrence and report it to the user.
It does still allow the bad data into the Text Box, but that’s not necessarily a bad thing.
Of course, you could create a method, or better yet an Extension Method, to handle this situation.
Maybe it’s because of the hard-coded nature of the validation messages, but it still doesn’t feel right to me. NET 3.5 SP1 we have just such an animal, the Custom Validation Rule.
Creating Custom Validation Rules Wouldn’t it be better to have a reusable piece of code to handle these similar situations? is an abstract class that we can inherit from to create a custom validation rule class of our own.