Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make input Textbox as currency format (WPF MVVM) [closed]

Tags:

mvvm

wpf

i am new in WPF, just start learning today. can anyone help me how to format the TextBox as currency format? which in my Textbox, can only be inputted by the numbers with 2 decimal point? Thanks.

like image 636
user2473454 Avatar asked Jun 11 '13 07:06

user2473454


2 Answers

Are you looking for something like this?:

<TextBox Text="{Binding Path=Txt, StringFormat=C}"/>
like image 187
rhe1980 Avatar answered Sep 26 '22 15:09

rhe1980


You can use something like this

 <TextBox TextAlignment="Right"
      Text="{Binding Price,
           UpdateSourceTrigger=PropertyChanged,
           StringFormat='#.00',
           ConverterCulture={x:Static sysglb:CultureInfo.CurrentCulture}}"/>

which forces the text to have right alignment and to have a format like 105.00 or 19.95 with decimal point/comma depending on user system settings. You can also add a currency sign to string format if applicable.

Edit: Sorry, I am spoiled with automatic importing of namespaces. In your top-level element (Usercontrol, Window, ...) add:

<UserControl x:Class="..."
     ...
     xmlns:sysglb="clr-namespace:System.Globalization;assembly=mscorlib"
     ...
>
like image 21
eMko Avatar answered Sep 25 '22 15:09

eMko