Binding.StringFormat does not adhere to CultureInfo.CurrentCulture

I am having a strange format with a currency issue when using data binding on a Windows phone.

I checked CultureInfo.CurrentCulture.NumberFormat.CurrencySymbol

and thisΒ£

When I do string.Format("{0:C}", 30.30)

, it renders correctly as well Β£30.30

.

So why does the following code generate $30.30

when using data binding?

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

      

+3


source to share


1 answer


I'm not familiar with the Windows SDK, but in WPF, StringFormat bindings are controlled using the Language property , rather than the current thread culture information. You can set it at the page level and all children will use the same language.

This illustrates how a language property changes the binding behavior regardless 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>

      

+1


source







All Articles