Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 resx file and now it seems that we need to use resw file. It's not a language resource file. My file is called ConfigResources.resw, it just contains one key : "ConfigFile" and a value : a string.

How can I access it from my code? I tried this without any luck:

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

Then how can I edit the value of the key inside from my code?

Thank you

like image 490
Thomas Salandre Avatar asked Dec 04 '22 14:12

Thomas Salandre


2 Answers

I created a project on CodePlex recently called ResW File Code Generator that simplifies using localized resources in code in windows store app project. It's a custom tool that automatically generates and updates a helper class similar to what ResX files used in the full version of .NET

like image 103
Christian Resma Helle Avatar answered Feb 10 '23 09:02

Christian Resma Helle


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

It should look something like this:

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

Alternately, if you're creating a cross-platform library you could also do it using the System.Resources.ResourceManager:

Although the System.Resources.ResourceManager class is included in the .NET for Windows Store apps, we do not recommend its use. Use ResourceManager only in libraries that are developed as Portable Class Library projects and that target multiple platforms.

Like this from here:

ResourceManager rm = new ResourceManager("Strings", typeof(Example).Assembly);
string timeString = rm.GetString("TimeHeader");
like image 27
N_A Avatar answered Feb 10 '23 08:02

N_A