Change the default delimiter and decimal separator in a binding

Let's say I have the number 1234567.89 . The number is displayed in the WPF text block. I am trying to apply the StringFormat attribute to the Text property so that the number is displayed as follows:

 1.234.567,89 

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

I tried setting numerous combinations for StringFormat , but to no avail. This is the last thing I came up with:

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

But the conclusion is wrong. In addition, using N2 or changing a culture is not an option. I would like to avoid converters if possible.

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

+5
c # wpf xaml string-formatting
Feb 21 '13 at
source share
1 answer

You do not need to change the culture. Just use String.Format with the 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 this in XAML, you can try:

 Text="{Binding SomeBinding, StringFormat={}{0:N}, ConverterCulture=de-DE}" 
+8
Feb 21 '13 at 10:57
source share



All Articles