在XAML中使用ReswFileCodeGenerator从.resw文件绑定字符串

Cri*_*126 4 c# xaml localization windows-runtime windows-phone-8.1

我尝试使用Multilingual应用工具包本地化我的Windows Universal App.因为您无法直接从XAML中的.resw文件绑定字符串,所以我使用了ReswFileCodeGenerator工具.它在代码背后效果很好,但在XAML中我无法做到这一点.

在Windows Phone 8.0中,我可以使用:

Text="{Binding Path=LocalizedResources.StringName, Source={StaticResource Strings}}"
Run Code Online (Sandbox Code Playgroud)

使用ReswFileGenerator工具在Windows(Phone)8.1中是否有类似的方法?

Dam*_*Arh 8

我仍然建议你按照Depechie的建议去做:使用x:Uid属性.

如果需要从代码中获取本地化字符串,只需.在资源名称中替换/.那么,在XAML中你会写:

<TextBlock x:Uid="appString" />
Run Code Online (Sandbox Code Playgroud)

在代码中你将使用:

var resourceLoader = new ResourceLoader();
var localizedText = resourceLoader.GetString("appString/Text");
Run Code Online (Sandbox Code Playgroud)