pastillman
pastillman

Reputation: 1134

Generic Number Validation Rule?

When using TextBox constrols bound to different number types (eg, uint, int, double etc), entering values that aren't compatible, produce user unfriendly error messages.

For example, using a TextBox bound to a uint and entering "-7", produces the error message "Value '-' cannot be converted".

So I'd like to go about creating a validation rule that produces more user friendly error messages.

The problem is that the validate override provides no contextual information about the type bound. Meaning that I would have to create a different rule for each type and then make sure I was using the right one in xaml, which is just horrible.

The only way I have found to get information about the bound type is to set the ValidationStep to UpdatedValue, but this is obviously no help as the value has been already updated at that point and won't even be called should it be incorrectly formatted.

So I'm wanting to know how I can validate a value before its actually set on the viewmodel, but with contextual information about the type itself so I can then use reflection to get values such as Min and Max etc

I'd also like to avoid a custom TextBox approach if possible as I think the idea could be used elsewhere too

Upvotes: 0

Views: 225

Answers (0)

Related Questions