Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Formatting textbox string for currency

I have a textbox in WPF and I would like to dynamically show the currency symbol, i.e. when the user edits the textbox and the textbox loses the 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 textbox is not binded to anything.

like image 461
MohdRash Avatar asked Feb 22 '23 07:02

MohdRash


2 Answers

this is the easiest approach

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

value is your double or decimal money but you said it's "not binded to anything" i can't see how is that possible but you can do it by code if you want like so

value.ToString("$#,##0.0000;$(#,##0.0000)");
like image 73
HB MAAM Avatar answered Feb 23 '23 22:02

HB MAAM


Look at the Masked TextBox that is part of the Extended WPF ToolKit. Or Google WPF Masked TextBox for other options.

like image 41
Mark Hall Avatar answered Feb 23 '23 21:02

Mark Hall