windows phone 7 – 本地化Windows Phone 7应用程序

前端之家收集整理的这篇文章主要介绍了windows phone 7 – 本地化Windows Phone 7应用程序前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
获取本地化的资源文件可以在 Windows Phone 7上运行有一些麻烦.这就是我在做什么:

>创建一个资源文件,比如说“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>
我写了一篇博客文章,提供了一系列 Globalization / Localization guides for WP7.链接.有一个 Windows Phone 7 in 7 Training video帮助我了解基础知识.之后,这只是一个学习如何做数据绑定的问题:

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:

  1. Open your primary XAML page (usually MainPage.xaml) in the Visual
    Studio designer

  2. Open 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.

  3. 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.

原文链接:https://www.f2er.com/windows/364020.html

猜你在找的Windows相关文章