How to access a specific resw resource file

For a Windows 8 application in C # / XAML, I need to access a specific ressource file. In WP7, I used the resx file, and now it seems that we need to use the resw file. This is not a language resource file. My file is called ConfigResources.resw, it contains only one key: "ConfigFile" and value: string.

How do I access it from my code? I tried this with no luck:

var storedConfigFile = Application.Current.Resources["ConfigResources"]; 

Then how can I change the key value inside my code?

thanks

+4
source share
3 answers

There is a sample that shows various ways to read resources in WinRT applications (i.e. from resw files).

+4
source

I recently created a CodePlex project, called a ResW file code generator , that simplifies the use of localized resources in code in a Windows Store app application. This is a custom tool that automatically generates and updates a helper class, similar to using ResX files in the full version of .NET.

+7
source

According to here , you need to use the Windows.ApplicationModel.Resources.ResourceLoader and Windows.ApplicationModel.Resources.Core namespace to interact with resw files.

It should look something like this:

 var loader = new Windows.ApplicationModel.Resources.ResourceLoader(); var text = loader.GetString("Farewell"); 

Alternatively, if you are creating a cross-platform library, you can also do this using System.Resources.ResourceManager :

Although the System.Resources.ResourceManager class is included in .NET for Windows Store applications, we do not recommend using it. use of the ResourceManager only in libraries that are developed as portable classes Library projects and aimed at several platforms.

How is it from here :

 ResourceManager rm = new ResourceManager("Strings", typeof(Example).Assembly); string timeString = rm.GetString("TimeHeader"); 
+5
source

Source: https://habr.com/ru/post/1432432/


All Articles