i dont know how to make my textbox from string to currency. I already do search on STO, google. but don't understand how to use it.
let's say i have one textbox. whenever it run the program, i key in inside the textbox. if i key in 1000, i want my textbox automatically change to 1,000. if i key in 10000, my textbox will looks like 10,000. but whenever i key in 100, my textbox will still 100.
here is my textbox xaml.
<TextBox Height="25" HorizontalAlignment="Left" Margin="126,223,0,0" Name="txtPrice"
VerticalAlignment="Top" Width="140" PreviewTextInput="txtPrice_PreviewTextInput" />
I ever done this before using vb.net, but now i'm using wpf. still new to wpf. any idea how to that? thanks.
Try this:-
<Style TargetType="{x:Type TextBox}">
<Setter Property="Text" Value="{SomeValue, StringFormat=C}" />
<Style.Triggers>
<Trigger Property="IsKeyboardFocusWithin" Value="True">
<Setter Property="Text" Value="{SomeValue, UpdateSourceTrigger=PropertyChanged}" />
</Trigger>
</Style.Triggers>
</Style>
Use the StringFormat
dependency property to format the way you want the string to be shown on UI. Try this -
<TextBox Text="{Binding YourBinding, StringFormat='##,#',
UpdateSourceTrigger=PropertyChanged}"/>
For more formats refer to this link from msdn - Custom Numeric Format
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