我在这里可能漏掉了什么。
我在VS2015中创建一个全新的WPF应用程序。我创建了一个资源'String1',并将其值设置为'fksdlfdskfs'。
我更新了默认的MainWindow.xaml.cs,使构造函数包含:
public MainWindow()
{
InitializeComponent();
this.Title = Properties.Resources.String1;
}
运行应用程序,发现它能很好地运作,我的窗口标题是fksdlfdskfs。
在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)]
所以我将以下内容添加到我的WpfApplication5.csproj文件中,并在VS中重新加载项目:
<UICulture>en-US</UICulture>
然后取消AssemblyInfo.cs中以下行的注释:
[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
如果我现在运行这个应用程序,它将不再运行,并且我会在读取资源的那一行得到以下异常:
如果我在AssemblyInfo.cs文件中将System.Resources.MissingManifestResourceException: 找不到适用于指定区域性或中性区域性的任何资源。请确保“WpfApplication5.Properties.Resources.en-US.resources”在编译时已经正确地嵌入或链接到程序集“WpfApplication5”中,或者需要加载并完全签名的所有卫星程序集都可用。
UltimateResourceFallbackLocation.Satellite
更改为UltimateResourceFallbackLocation.MainAssembly
,我将得到以下异常:我做错了什么或者我缺少了什么?System.IO.IOException: 无法找到资源'mainwindow.xaml'