可本地化的WPF应用程序 - UICulture设置导致资源问题

0xb*_*00d 3 c# wpf localization currentuiculture visual-studio

我想创建一个可本地化的WPF应用程序.我按照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.
Run Code Online (Sandbox Code Playgroud)

完成此操作后,我的应用程序不再启动了.我正在使用自定义App类:

namespace Namespace
{
    public partial class App : Application
    {
        [STAThread()]
        [SecurityPermission(SecurityAction.LinkDemand)]
        public static void Main()
        {
            var app = new App();

            app.InitializeComponent();
            app.Run();
        }


        [DebuggerNonUserCode()]
        public void InitializeComponent()
        {
            this.StartupUri = new Uri("MainWindow.xaml", UriKind.Relative);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

 

<ns:App
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:ns="clr-namespace:Namespace">

</ns:App>
Run Code Online (Sandbox Code Playgroud)

一切都运转良好.我假设配置的UICulture设置与为MainWindow.xaml指定的设置之间存在某种不匹配,但我不知道如何修复它.

小智 10

我有类似的效果; 在AssemblyInfo.cs中,该NeutralResourcesLanguage属性需要UltimateResourceFallbackLocation.Satellite参数:

// Uncommenting the following line --> OK
[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
// Uncommenting the following line --> IOException: Cannot locate resource 'app.xaml'.
// [assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.MainAssembly)]
// Uncommenting the following line --> IOException: Cannot locate resource 'app.xaml'.
// [assembly: NeutralResourcesLanguage("en-US")]
Run Code Online (Sandbox Code Playgroud)