0

I am binding a float property to my TextBox control. Thats working correct if I am using "en" as my language Preference. Entering a number "1.123" is correctly parsed.

If I Switch mur culture to "de" nothing changes in the TextBox (and TextBlocks). Still everything is formatted with a ".".

Entering a number via the "Numeric" Keyboard of WinRT is using the "," as a seperator. But the Training Digits will not be part of the number after Focus lost (and the bound property is updated. So "1,234" should be parsed internaly as "1.234". But ist converted to "1".

The app.xaml.cs contains some more initialisation for ensuring the culture is set to the right language. The allowed languages are ("en" and "de" (*,proj file. The CultureInfo.CurrentCulture is correctly set to "de" if you break into debugger.

public App()
{
    Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride =     CultureInfo.CurrentCulture.Name;
    CultureInfo.DefaultThreadCurrentCulture = CultureInfo.CurrentCulture;
    CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.CurrentCulture;
Obiwan007
  • 646
  • 1
  • 8
  • 20
  • How are you changing the culture? If changing the user's culture via Windows, are you ensuring the app is terminated and then restarting it? The [CultureInfo.CurrentCulture](http://msdn.microsoft.com/en-us/library/windows/apps/system.globalization.cultureinfo.currentculture(v=vs.110).aspx) says that the culture is set only on thread creation. – Edward Brey Aug 09 '12 at 15:07
  • I am Setting the language through Windows. The App.cs contains additional Settings for ensuring the correct language is assigned: – Obiwan007 Aug 10 '12 at 09:30

2 Answers2

1

Setting PrimaryLanguageOverride, DefaultThreadCurrentCulture, and DefaultThreadCurrentUICulture in the Application constructor has no effect, since they only apply to new threads. However, your main UI thread has already been created an had its culture set by the time the constructor is entered.

To force a change to the existing UI thread, you'd have to set Thread.CurrentCulture as documented in CultureInfo.CurrentCulture; however, WinRT does not support the Thread class.

This leads to the question of why any manual cultural changes are required at all. The app should automatically pick up the user's Windows culture at startup or upon resuming from hibernation.

Edward Brey
  • 40,302
  • 20
  • 199
  • 253
  • Thread.CurrentCulture is unfortunatels not supported in WinRT when I am not completely wrong... WPF !=WinRT. I think the culture is set correctly drom the system - but the formatting and parsing of bound numbers is not correct. – Obiwan007 Aug 10 '12 at 17:24
  • Good point about not being able to set the culture on an existing thread in WinRT. I updated by answer accordingly. Why the system culture wouldn't "just work" with data binding remains a mystery. – Edward Brey Aug 10 '12 at 21:23
0

To get the InvariantCulture settings we can use,

"ApplicationLanguages.PrimaryLanguageOverride = CultureInfo.InvariantCulture.TwoLetterISOLanguageName;"

This worked for me.

Mei
  • 21
  • 3