strange Problem with WPF Textbox stringformat - Cursor moves back

Posted by Emad on Stack Overflow See other posts from Stack Overflow or by Emad
Published on 2010-05-17T19:26:18Z Indexed on 2010/05/17 19:31 UTC
Read the original article Hit count: 335

Filed under:
|

I am using WPF 4.0 TextBox and binding. I am using StringFormat to format the number as currency. the XAML looks like this:

<TextBox Text="{Binding Path=ValueProperty, ValidatesOnDataErrors=True, ValidatesOnExceptions=True, StringFormat={}{0:C}, UpdateSourceTrigger=PropertyChanged}">
</TextBox>

Everything seems to work correctly except for a strange behavior: When for example a user types in 12: right after typing 1, the value in the textbox becomes $1.00 and the weird thing is the the cursor is moved to be between the $ and the 1. So when a user simply types in 12, the result becomes $21.00.

How can I fix this strange behavior?

© Stack Overflow or respective owner

Related posts about wpf

Related posts about databinding