Changing the default thousand and decimal separator in a binding

こ雲淡風輕ζ 提交于 2019-12-12 10:39:47

问题


Let's say I have a number 1234567.89. The number is displayed in a WPF TextBlock. I am trying to apply StringFormat attribute to the Text property so that the number would be displayed like:

1.234.567,89

As you can see, the thousand and decimal separators are inverted from the invariant culture specification.

I've tried setting numerous combinations for the StringFormat, but without success. This is the latest I came up with:

Text="{Binding SomeBinding, StringFormat={}{0:#'.'##0','00}}"

But the output isn't correct. Also, using N2 or changing culture isn't an option. I would like to avoid converters if possible.

So, is there a way to change the default separators through XAML?


回答1:


You don't have to change the culture. Just use String.Format with specified culture (de-DE should be fine):

string output = String.Format(new CultureInfo("de-DE"), "{0:N}", yourDoubleValue);

Output: 9.164,32

If you want to do it in XAML, you could try:

Text="{Binding SomeBinding, StringFormat={}{0:N}, ConverterCulture=de-DE}"


来源:https://stackoverflow.com/questions/15000191/changing-the-default-thousand-and-decimal-separator-in-a-binding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!