I have a TextBox
that is bound to an integer. This obviously means that if the user enters something that cannot be parsed to an int, there will be a binding error.
This is fine and is expected. However, the error in the UI is displayed as something like
Value ‘ABCD’ could not be converted
I would like to change this message as it’s not very intuitive. I also need to localise it for different languages.
I appreciate that one way of doing this is to add a ValidationRule
to the binding. However, I do not want to do that for every single place I use a TextBox
bound to something other than a string. This approach also requires you know the type you’re binding to (it could be any type in my case, e.g any numeric type, not just an int)
Another approach is to prevent certain key presses (e.g do not accept azAZ chars), but I am not a fan of this approach. I would prefer to simply display a message.
So I am wondering, is it possible to subclass TextBox
and do something custom to get the behaviour I want?