Make an input Text field as a currency format (WPF MVVM)

I am new to WPF, now starting to learn. can someone help me how to format TextBox as currency format? which in my text box can only be entered with numbers with 2 decimal points? Thanks.

+7
source share
2 answers

You are looking for something like this:

<TextBox Text="{Binding Path=Txt, StringFormat=C}"/> 
+10
source

You can use something like this

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

which makes the text have the correct alignment and have the format 105.00 or 19.95 with a decimal point / comma, depending on the settings of the user system. You can also add a currency sign in string format, if applicable.

Edit: Sorry, I'm spoiled by the automatic import of namespaces. In the top-level element (Usercontrol, Window, ...) add:

 <UserControl x:Class="..." ... xmlns:sysglb="clr-namespace:System.Globalization;assembly=mscorlib" ... > 
+3
source

All Articles