Is there any decent way to get a WPF control which is bound to a decimal
value?
When I just bind the TextBox
or DataGridTextColumn
to a decimal
, data entry is a problem.
<TextBox Text="{Binding MyDecimal, UpdateSourceTrigger=PropertyChanged,
ValidatesOnDataErrors=True}"/>
When I try to enter "0,5" in this TextBox
I'll get "5" as a result. It is nearly impossible to enter "0,5" at all (apart from entering 1,5 and replacing the "1" with a "0").
When I use StringFormat
, data entry is only slightly improved:
<TextBox Text="{Binding MyDecimal, StringFormat=F1, UpdateSourceTrigger=PropertyChanged,
ValidatesOnDataErrors=True}"/>
Now, when I try to enter "0,5" I'll end up with "0,5,0", which still is wrong but at least I can remove the trailing ",0" without much difficulty.
Still, entering decimal
types using WPF is very awkward, because these TextBox
es are very prone to data entry errors, which is a real pain especially for values!
So what am I supposed to use for decimal data entry in WPF? Or does Microsoft not support decimal data??