Binding.StringFormat doesn't adhere to CultureInfo.CurrentCulture

159 views Asked by At

I'm experiencing a weird format with currency issue when using data-binding on windows phone.

I have checked the CultureInfo.CurrentCulture.NumberFormat.CurrencySymbol and this is £

When I do string.Format("{0:C}", 30.30) it displays correctly also with £30.30.

So why would the following code produce $30.30 when using data binding?

Binding binding1 = new Binding(somePropertyName);
binding1.StringFormat = "{0:C}";
1

There are 1 answers

0
Lorentz Vedeler On BEST ANSWER

I am not that familiar with the windows phone SDK, but in WPF the StringFormat of bindings are controlled with the Language property, rather than the current thread culture info. You can set it at the page level and all children will use the same language.

This illustrates how the language property changes the behavior of a binding independent of the current thread:

<StackPanel Language="nb-NO">
    <Slider Name="slider" />
    <TextBlock Text="{Binding ElementName=slider, Path=Value, StringFormat=C2}" />
    <TextBlock Language="en-US" Text="{Binding ElementName=slider, Path=Value, StringFormat=C2}" />
</StackPanel>