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.
Are you looking for something like this?:
<TextBox Text="{Binding Path=Txt, StringFormat=C}"/>
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"
...
>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With