不幸的是描述的解决方法在菲尔·霍夫博客上 http://blogs.msdn.com/b/philliphoff/archive/2014/11/19/missingmanifestresourceexception-when-using-portable-class-libraries-in-winrt.aspx对我来说效果不太好。
我已经开发了自己的解决方法。事实证明,如果您仅使用 .resx 文件来存储字符串值,那么您可以轻松地将它们转换为 .resw。
因此,我正在做的就是自动从 PCL 转换所有 .resx 文件,并将其放入 Windows Phone 8.1 项目中的本机结构化文件夹中,并使用我编写的这个工具在每次构建时刷新它们。
https://github.com/konradbartecki/ResxHell https://github.com/konradbartecki/ResxHell
然后我可以通过这样的代码轻松访问我的字符串资源
var resourceLoader = new ResourceLoader();
var localizedText = resourceLoader.GetString("MyCustomReswFile/MyCustom");
为了实现良好的绑定,我最终创建了 ValueConventer 和小型本地化帮助程序类,看看这个要点:从 .resw 文件绑定示例 https://gist.github.com/konradbartecki/3e315c3b24f5eb1dd413
使用它,您可以在 xaml 页面中执行以下操作:
//For resource in file Page.Login.resw and string ID "NotUserYet"
<TextBlock Text="{Binding ConverterParameter=Page.Login/NotUserYet, Converter={StaticResource ResString}, Mode=OneWay, Source={StaticResource ResString}}"/>
or
string localizedtext = LocalizationHelper.GetString("MyCustomReswFile", "MyStringId");