1

I'm working on a WPF / C# app that needs to be culturally aware for globalization. I already have resource files and a bindable translation manager that is all working as expected.

At the moment I'm doing this:

 Thread.CurrentThread.CurrentUICulture = _currentlyConfiguredUiCulture;
 Thread.CurrentThread.CurrentCulture = _currentlyConfiguredUiCulture;

This is all wired up in the UI like this:

TranslationManager.Instance.LanguageChanged += TranslationManager_LanguageChanged;

private void TranslationManager_LanguageChanged(object sender, EventArgs e)
{
    Thread.CurrentThread.CurrentUICulture = TranslationManager.Instance.CurrentLanguage;
    Thread.CurrentThread.CurrentCulture = TranslationManager.Instance.CurrentLanguage;
}

This all works sweet!

The problem is when the app is started my machine locale is "en-GB" and this is correctly set using the code shown above. However, when I hit some code I have in an IValueConverter class dealing with dates:

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
    if (value != null)
    {
        return DateTime.Parse(value.ToString(), culture);
    }

    return null;
}

The culture property here is always "en-US" ... how on earth is this occurring? How do I fix this so that the app is actually using the correct system culture?

4

2 に答える 2

2

このリンクには、以下を追加する必要がある可能性があることが記載されています。

FrameworkElement.LanguageProperty.OverrideMetadata(
  typeof(FrameworkElement), 
  new FrameworkPropertyMetadata(
    XmlLanguage.GetLanguage(
      System.Globalization.CultureInfo.CurrentCulture.IetfLanguageTag)));
于 2013-09-24T14:23:52.393 に答える