Reputation:
I have a simple MVVM application containing a TextBox that is databound with a double property in the ViewModel. The input scope of the TextBox is set to NumbersOnly
. The problem is that if I enter values like 4,23
the property is rounded to 4.0, so I lose the information behind the decimal separator. How can I avoid this?
The app correctly recognizes my region and sets the decimal separator to ,
as is it the case in Germany. Can this be the cause for the problem? I couldn't do much testing yet but maybe someone already ran across this behaviour (though I didn't find any help yet).
Upvotes: 1
Views: 111
Reputation: 1661
When You bind data to Your TextBox You can also set StringFormat:
<TextBox Text="{Binding path=property, StringFormat=N2}/> // n2 means 2 decimal places
Upvotes: 1