>创建一个资源文件,比如说“Strings.resx”(Build Action:Compile)
>创建一个键,说“TestKey”,默认值为空字符串
>在同一个文件夹中添加一个英文资源文件,其值为“一些英文字符串”:Strings.en-us.resx(Build Action:Embedded Resource)
>在同一文件夹中添加日语资源文件,值为“一些日语字符串”:Strings.ja-jp.resx(构建操作:嵌入式资源)
在我的PC Silverlight,WPF应用程序,当我更改Thread.CurrentThread.CurrentCulture工作正常.但在手机中,我总是似乎得到了Strings.resx文件中的一个空字符串.
我已经尝试使用设计器生成的代码,并用手接线资源管理器,似乎并不重要.这是我的代码:
Type t = typeof(Strings); _resourceManager = new ResourceManager( t.Namespace + "." + t.Name,t.Assembly); _resourceManager.GetString("TestKey");
告诉我手机支持的本地化资源…;>我究竟做错了什么?谢谢!
更新:感谢Olivier转发链接.我也看到了,但错过了重要的一步.我没有将“SupportedCultures”节点添加到我的csproj.做出了所有的区别 – 希望别人不会松动两个小时,试图像我这样做.
<SupportedCultures>de-DE;es-ES;</SupportedCultures>
The MSDN article shows you how to
setup the files and create the
LocalizedStrings class,but they then
assume that you know how to use that
class for data binding. Visual Studio
2010 and Silverlight handle data
binding differently than Winforms,and
it gets even more confusing since XAML
also has it’s own definition of
Resources that are different then the
.NET resources we just created.
Silverlight also uses the term
Resource to refer to files that use
the the Build Action of “Content”,as
these files get wrapped up into the
.XAP file similar to how files with
Build Action of “Resource” get
embedded into the .Dll assembly (ex:
loading an image from content or
resource files). I found that instead
of using the Text=”{Binding
Path=resourceFile.resourceName,
Source={StaticResource
Localizedresources }}” XAML Syntax it
was easier to use the following steps:
Open your primary XAML page (usually MainPage.xaml) in the Visual
Studio designerOpen the properties for the PhoneApplicationPage and set the
DataContext to be
Application.Resources –>
LocalizedStrings. NOTE: if you already
are using a DataContext object,then
you should integrate the
LocalizedStrings class into that
object so that it has localization
support.Once the Page’s DataContext has been set you can change the data binding for any control on the page by simply selecting the property (ex: text,checked,etc),selecting “Apply Data Binding…”,and setting the Path to Localizedresources.BtnText or whatever the name of the desired resource value is.