英文:
How can I format a textbox number to curreny with 2 decimal places?
问题
You can format the text of a TextBlock as currency with two decimal places by using the StringFormat
property in your XAML code. Here's how you can modify your code:
<TextBlock Text="{x:Bind ViewModel.Premium, Mode=TwoWay, StringFormat='{}{0:C2}'}" />
This will format the value of ViewModel.Premium
as currency with two decimal places, and it will automatically detect the configured global/thread currency.
There is no direct property for currency formatting in the TextBlock
itself, but you can achieve the desired formatting using the StringFormat
as shown above.
英文:
How can I format the text of a textblock as currency with two decimal places?
<TextBlock Text="{x:Bind ViewModel.Premium, Mode=TwoWay}"/>
I want to configure something like DisplayFormat="c2" and the result should be for instance 10,23$
Something that detects the configured global/thread currency.
I did not find a property under https://learn.microsoft.com/de-de/uwp/api/windows.ui.xaml.controls.textbox?view=winrt-22621
or a binding feature that allows that. Not sure if the numberbox would be appropriate. I need it only readable as info for the user.
答案1
得分: 0
You can use function binding, like this:
<Window xmlns:sys="using:System" ...>
...
<TextBlock Text="{x:Bind sys:String.Format('{0:C2}', ViewModel.Premium)}" />
...
</Window>
PS: can't be TwoWay in the case since it's now a computed value
英文:
You can use function binding, like this:
<Window xmlns:sys="using:System" ...>
...
<TextBlock Text="{x:Bind sys:String.Format('{0:C2}', ViewModel.Premium)}" />
...
</Window>
PS: can't be TwoWay in the case since it's now a computed value
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论