1

我在 WPF 项目(VS 2008)的 Properties 文件夹中有两个资源文件:

  • 资源.resx
  • 资源.de-DE.resx

选择文化“de-DE”不起作用(没有错误,但始终使用来自“Resources.resx”的字符串):

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

但是:如果我将“Resources.de-DE.resx”重命名为“Resources.fr-CA.resx”或“Resources.en-US.resx”

然后通过设置它

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

有用!!但为什么!?神秘...

4

1 回答 1

0

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...

于 2010-09-27T16:29:12.517 回答