Using resw application file from background task

I am working on a modern user interface and am currently trying to access the application resource file (Resources.resw) from backgroundtask. Both options are in different projects in the same solution. I tried like this:

ResourceLoader resources = new ResourceLoader("MyApp/Resources"); 

But I have arror since it cannot get to the resource map.

Is there any way to do this?

+6
source share
4 answers

In case anyone meets this.

At UWP, it seems like you don’t have to do anything special to make this work. If the .resw files .resw included in the main UWP project, you can use the resource loader to extract them even from the background task build. For a resource string called LiveNotifications-ItemComplete, this will be the following:

var resource = new ResourceLoader().GetString("LiveNotifications-ItemCompleted");

Hope this helps!

+2
source

Try using only the resource file name. If the name is MyResources.resw, then use:

 ResourceLoader resources = new ResourceLoader("MyResources"); 
+1
source

Although this is an old post, I thought I would post my results, since none of the suggestions in this post worked for me when I tried to use it with my background task in my UWP application for Windows 10.

How I achieved this was as follows:

 string str = ResourceLoader.GetForViewIndependentUse("Resources"). GetString("MyLocalizedKey"); 

Where

  • "Resources" is the name of the .resw file in your application "App \ String \ en-US" or "App \ Strings \ fr-FR".

and

  • "MyLocalizedKey" is the actual key of the value you want to get from the resource file.

Now remember that if you use this method, you will need to put all the lines of your BackgroundTask into the main application.

Hope this helps.

+1
source

I think that what you are trying to do is simply impossible. Perhaps, access to Resw will be possible only within the framework of the store application project. At least this is my observation, and I tried everything, as far as I know.

However, I can offer a solution if you want to pass parameters to a background job. Add the resw file to the Windows Store app project. When you register a background task, write your settings (or everything you need to go to the background task) to the local settings of your device. Then from your background task read the same parameter from the local settings.

Not bad, but it works well. I apologize if this does not help.

0
source

All Articles