Localizing Windows Phone 7 App

后端 未结 2 1824
猫巷女王i
猫巷女王i 2021-02-05 23:32

I\'m having a little trouble getting localized resources files to work on Windows Phone 7. Here\'s what I\'m doing:

  1. Create a resource file, say \"Strings.resx\"
2条回答
  •  有刺的猬
    2021-02-06 00:07

    I wrote a blog post that provides links to a bunch of Globalization / Localization guides for WP7. There is a Windows Phone 7 in 7 Training video that helped me understand the basics. After that it was simply a matter of learning how to do databinding:

    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.

提交回复
热议问题