Silverlight 无法正确读取我的资源文件
我为英语 (MyResourcesFile1.resx) 和法语 (MyResourcesFile1.fr.resx) 创建了 .resx 文件。两者都有公共的访问修饰符
,并且都是嵌入式资源
。
在 app.xaml.cs 中,甚至 Application_Startup 包含:
var languageInfo = new CultureInfo("fr");
Thread.CurrentThread.CurrentCulture = languageInfo;
Thread.CurrentThread.CurrentUICulture = languageInfo;
在 Silverlight 代码的许多地方,我使用 Visual Studio 提供的生成属性。
string myString = MyResourcesFile1.MyPropertyValue;
不幸的是,它只从英文文件中获取本地化的字符串。为什么?
I have .resx file created for english (MyResourcesFile1.resx) and french (MyResourcesFile1.fr.resx). Both have the Access Modifier
to Public and they are both Embedded Resource
.
In the app.xaml.cs the even Application_Startup contain :
var languageInfo = new CultureInfo("fr");
Thread.CurrentThread.CurrentCulture = languageInfo;
Thread.CurrentThread.CurrentUICulture = languageInfo;
In many place in the Silverlight code I use the generated property that Visual Studio has provide.
string myString = MyResourcesFile1.MyPropertyValue;
Unfortunately, it only takes the localized string from the english file. Why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我通过阅读大量的微软文档最终让它工作起来。
Visual Studio 2010 还没有用于添加 Silverlight 项目支持的语言的菜单。为了让您的应用程序能够使用所有资源文件,需要对其进行修改。第一步是使用记事本打开项目解决方案。完成后,搜索SupportedCultures。在括号内您可以添加所需的语言(无需添加默认语言)。所以我的现在看起来像这样:
重新加载项目并编译。如果您像我在应用程序启动中所做的那样设置线程,则资源将正确加载并显示。我认为它不能动态更改,但对我来说没有必要。
I make it works finally by reading a lot of Microsoft Documentation.
Visual Studio 2010 doesn't have (yet) a menu to add the supported language for Silverlight project. To have your application working with all your resources files, it needs to be modified. The first step is to open the project solution with NotePad. Once it's done, search for SupportedCultures. Inside the bracket you can add the desired language (no need to add the default one). So mine looks like that now:
Reload the project and compile. If you set the thread like I were doing in the Application Startup, the resource is correctly loaded and displayed. I think it cannot be dynamically changed but it wasn't necessary for me.
其中一个选项是在 App.xaml.cs 中设置文化,您可以在其中设置对象标记。
One of the options is insted of settings culture in App.xaml.cs, you can set in it the object tag.