字符串资源数据绑定在Windows 8

字符串资源数据绑定在Windows 8

问题描述:

.resw

字符串资源数据在Windows 8字符串资源数据绑定在Windows 8

绑定在Windows Phone的我用如下:

  1. 创建AppStrings.resx,并把所有的字符串就可以了。
  2. 创建类StringResources,返回实例AppStrings.resx的字段。
  3. StringResources添加到​​。

StringResources.cs

public class StringResources 
    { 
     private static AppStrings _resources; 

     public static AppStrings LocalizedResources 
     { 
      get { return _resources ?? (_resources = new AppStrings()); } 
     } 
    } 

在App.xaml中

<Application.Resources> 
     <ResourceDictionary> 
      <res:StringResources x:Key="Strings"/> 
     </ResourceDictionary> 
    </Application.Resources> 

使用来自像XAML我的资源。

Text="{Binding Path=LocalizedResources.StringName, Source={StaticResource Strings}}" 

所有的伟大工程,但我不能这样做在Windows 8
我在Windows上使用搜索字符串资源使用DataBinding的类似的方式8.

注:
我检查MSDN Sample,但无法找到我所需要的。
我也检查ResW File Code Generator,这是可行的方式,但很牵强。

您可以使用与WP相同的方法。 Visual Studio扩展PublicResXFileCodeGenerator用于生成一个强类型类,其静态属性对应于WinPhone应用程序中resx文件中的所有键。但由于某些原因,默认情况下W8没有这样的工具。

ResW文件代码生成器Visual Studio extesion正在做同样的事情。

http://visualstudiogallery.msdn.microsoft.com/3ab88efd-1afb-4ff5-9faf-8825a282596a

安装它,然后你只需要设置“自定义工具”字段ReswFileCodeGenerator(在默认AppStrings.resw文件的属性),并设置自定义工具命名空间提供一个名称空间,您AppStrings类。 它会自动生成AppStrings类,然后你可以在WP中使用它。

注意:该扩展再生AppStrings CALSS每次你改变你AppString.resw文件和VS 2013年将迎来构造“新资源加载(‘AppStrings’)”为废弃的时间。您需要使用独立于CoreWindow的方法ResourceLoader.GetForViewIndependentUse(“AppString”)来代替(GetForCurrentView(“AppString”)不起作用)。