加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

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

发布时间:2020-12-14 04:32:27 所属栏目:Windows 来源:网络整理
导读:获取本地化的资源文件可以在 Windows Phone 7上运行有一些麻烦.这就是我在做什么: 创建一个资源文件,比如说“Strings.resx”(Build Action:Compile) 创建一个键,说“TestKey”,默认值为空字符串 在同一个文件夹中添加一个英文资源文件,其值为“一些英文字
获取本地化的资源文件可以在 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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读