Text string formatting for currency

I have a text box in WPF and I would like to dynamically display a currency symbol, i.e. when the user edits the text field and the text field loses focus, the currency symbol is automatically inserted at the end (beginning). I prefer it in XAML rather than hard coding. I would like to mention that my text box is not attached to anything.

+4
source share
2 answers

this is the easiest approach

<TextBox Text="{Binding Value, StringFormat='$#,##0.0000;$(#,##0.0000)'}" /> 

the value is your double or decimal money, but you said it was "not attached to anything." I don’t see how this is possible, but you can do it by code if you want to.

 value.ToString("$#,##0.0000;$(#,##0.0000)"); 
+4
source

Take a look at Masked TextBox , which is part of the Extended WPF ToolKit . Or Google WPF Masked TextBox for other options.

+2
source

Source: https://habr.com/ru/post/1398579/


All Articles