I want a text box in a WPF form into which the user can enter a currency amount (e.g. $12.34)
I want to be able to give them an error message if they type in rubbish (e.g. "freds cash")
I want to be able to validate for ranges (so they can't for example, enter -ve numbers )
My 1st thought was to bind a standard textbox to my data property, which is a Decimal?, which doesn't work very well, as if the user types rubbish, an exception is thrown which (as far as I can ascertain) I can't catch!) I know I can display an error message/highlight the control if this happens, but this means that what is shown on the screen doesn't match what is in the property that I'm binding to - so what happens if the user now clicks the SAVE button? it saves the 'old' value, not what's on the screen, that's what!
Solutions I have seen include only binding to strings, and then validating the user input in the setter of those strings. Josh Smith does this here[^] While I like this idea, I feel a little uncomfortable - I'd really like to bind to the 'real' data and not a string representation of it.
Other solutions I came across included karl's solution here[^] which looks very interesting.
But I figure, WPF has been around for a while, so surely there's some accepted way of entering monetary amounts?
Am I missing something really obvious, so obvious that nobody's blogging about it? Or, am I just crap at Googling? Or, do I need to look at Josh or Karl's solution and use one of them? Or, is there a better way?