WPF C#上的货币文本框 [英] currency textbox on wpf c#
问题描述
我不知道如何使我的文本框从字符串转换为货币.我已经在Google的STO上搜索过.但是不知道如何使用它.
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.
假设我有一个文本框.每当它运行该程序时,我都会在文本框中键入内容.如果我输入1000,我希望我的文本框自动更改为1000.如果我输入10000,我的文本框将看起来像10,000.但是只要我输入100,我的文本框仍会是100.
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.
这是我的文本框xaml.
here is my textbox xaml.
<TextBox Height="25" HorizontalAlignment="Left" Margin="126,223,0,0" Name="txtPrice"
VerticalAlignment="Top" Width="140" PreviewTextInput="txtPrice_PreviewTextInput" />
我曾经在使用vb.net之前完成过此操作,但现在我正在使用wpf.对wpf还是个新手.任何想法如何?谢谢.
I ever done this before using vb.net, but now i'm using wpf. still new to wpf. any idea how to that? thanks.
推荐答案
使用 StringFormat
依赖项属性来格式化希望在UI上显示字符串的方式.试试这个-
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}"/>
有关更多格式,请参阅msdn中的此链接-自定义数字格式
For more formats refer to this link from msdn - Custom Numeric Format
这篇关于WPF C#上的货币文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!