Is it possible to use a portable library with localized resources in a Universal app?

前端 未结 6 1076
夕颜
夕颜 2021-02-04 12:08

(There\'s a link at the bottom to a solution with repro of the problem.)

I\'ve been using a portable library with .resx resources for quite some time as it worked for bo

相关标签:
6条回答
  • 2021-02-04 12:14

    Unfortunately the workaround described on Phil Hoff blog did not work for me too well. I have developed my own workaround. It turns out if you are using .resx files to store string values only, then you can easily convert them to .resw and use natively in Windows Phone 8.1.

    So what I am doing is copying and converting resources from PCL and placing as native .resw resources in Windows Phone project every build automatically using the tool I made - ResxHell. Just follow the instructions on the repository and you can then reach resources like this

    var resourceLoader = new ResourceLoader();
    var localizedText = resourceLoader.GetString("MyCustomReswFile/MyStringId");
    

    For nice binding I ended up creating ValueConventer and small localization helper class, take a look at this gist: Binding from .resw files example

    With the use of that you can do following in your xaml pages:

    //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");

    0 讨论(0)
  • 2021-02-04 12:21

    You can have .resx files in pcls, you just have to use the workaround explained on http://blogs.msdn.com/b/philliphoff/archive/2014/11/19/missingmanifestresourceexception-when-using-portable-class-libraries-in-winrt.aspx

    Even with the latest VS 2013 (update 5) the mdil error will appear when trying to deploy Release packages.

    MdilXapCompile.exe failed with error code 1004

    To work around it you must compile your app using the store option and then use the Application Deployment tool to actually deploy it to the device.

    0 讨论(0)
  • 2021-02-04 12:26

    In the end, it seems you can't use PCL library with localized resources using .resx files in the WP part of a Universal app. At least it's not trivial.

    There were runtime problems when the app is build in Realese configuration, which I couldn't resolve, so I decided to change to .resw resources. This solved my problems, of course, but I had to duplicate the resources, which is what I was trying to avoid.

    0 讨论(0)
  • 2021-02-04 12:28

    I found this is already reported to ms connect

    https://connect.microsoft.com/VisualStudio/feedback/details/991028/issue-using-resx-files-on-winrt-apps-windows-phone-and-windows

    and there is a workaround I haven't tried yet.

    http://blogs.msdn.com/b/philliphoff/archive/2014/11/19/missingmanifestresourceexception-when-using-portable-class-libraries-in-winrt.aspx

    Unfortunatelly it has not been fixed so far.

    0 讨论(0)
  • 2021-02-04 12:30

    Had the same problem. I tried deploying via Windows Phone Deployment Tool and it worked. So instead of using Visual Studio to deploy: create packages and put them on phone and it works!!

    0 讨论(0)
  • 2021-02-04 12:39

    You certainly unchecked the "Build" checkbox in the Configuration Manager, that's why the resources are not copied automatically. Check it and it will works.

    0 讨论(0)
提交回复
热议问题