Silverlight doesn't read my resource file correctly

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?


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:

<SupportedCultures>fr
</SupportedCultures>

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中的设置文化,您可以在其中设置对象标签。

<object ...>
     ...
     <param name="culture" value="de-de" />
     <param name="uiculture" value="de-de" />
    ...
</object>
链接地址: http://www.djcxy.com/p/95376.html

上一篇: 如何解决.net WinForm对话本地化问题

下一篇: Silverlight不会正确读取我的资源文件