代码之家  ›  专栏  ›  技术社区  ›  AidanH

“找不到资源'mainwindow.xaml'。”论UI文化的变迁

  •  0
  • AidanH  · 技术社区  · 6 年前

    我的程序设置如下:

    • 逻辑/交互项目
    • 示例UI项目(简单视图,其他不多)

    逻辑/交互项目具有各种不同语言的资源文件(例如“Resources.de.resx”、“Resources.ja.resx”等),而示例项目只有一个资源文件('Resources.resx')。

    示例项目可以正常运行和启动,无需修改,但当我将以下行添加到示例项目中时:

                Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("fr");
    

    我不断得到以下错误:

    System.IO.IOException: 'Cannot locate resource '<resource-name>.xaml'
    

    我真的不确定改变UI文化的后果,尤其是资源文件和本地化的工作方式——因此任何关于本地化的改变为什么会导致资源错误的指针都是非常有用的。

    1 回复  |  直到 6 年前
        1
  •  1
  •   Txelu    5 年前

    NeutralResourcesLanguage AssemblyInfo.cs . 打开 汇编信息。反恐精英 对该设置进行文件查找。您通常会看到以下评论:

    //In order to begin building localizable applications, set
    //<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file
    //inside a <PropertyGroup>.  For example, if you are using US english
    //in your source files, set the <UICulture> to en-US.  Then uncomment
    //the NeutralResourceLanguage attribute below.  Update the "en-US" in
    //the line below to match the UICulture setting in the project file.
    
    //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
    

    所以你必须 取消注释定义NeutralResourcesLanguage的最新一行 并确保该行中的语言代码与您的中性语言完全匹配。例如,如果你选择 "fr" 作为应用程序中的中性语言,您不能在那里设置 "fr-FR"

    第二个参数告诉应用程序在何处查找本地化资源DLL中未包含的资源。两个可用选项是:

    • UltimateResourceCallBackLocation。mainsassembly:当您没有使用中性语言的附属dll并且所有内容都保存在主程序集中时,需要使用此选项。

    es-ES 但我只是在那里设置的 es Satellite ,因此我猜未定义时的默认值为 MainAssembly .