views:

304

answers:

2

i have two Resources files in the Properties folder of a WPF-project (VS 2008):

  • Resources.resx
  • Resources.de-DE.resx

Selecting the culture "de-DE" does not work (no error, but always the strings from "Resources.resx" are used):

public App()
    {
        UntitledProject2.Properties.Resources.Culture = new CultureInfo("de-DE");
    }

BUT: if I rename "Resources.de-DE.resx" to "Resources.fr-CA.resx" or "Resources.en-US.resx"

and then set it via

UntitledProject2.Properties.Resources.Culture = new CultureInfo("fr-CA");

it works!! But why!? Mysterious...

A: 

Same here in VS 2010. :-(

Rick Beerendonk
A: 

By default, WPF will always use "en-US"; at least it did the last time I checked (which was .net 3.5). If you want WPF to instead use the culture currently set by the system, you would execute this code block:

FrameworkElement.LanguageProperty.OverrideMetadata(
  typeof(FrameworkElement),
  new FrameworkPropertyMetadata(
      XmlLanguage.GetLanguage(
      CultureInfo.CurrentCulture.IetfLanguageTag)));

This will override the default value used for the FrameworkElement's Language dependency property, which, again, is "en-US" by default.

Execute this code once and early on in the lifetime of your application. AFter that, you shouldn't have to worry about it again, unless you expect your user to be switching the culture in the middle of program execution...

Matt Weber