String-Resources in Windows Store apps

1) Create a Resource file (Resources.resx) in your project.

2) Add Keys and Values
key1 => Value for Key Nr. 1
key2.Text => Value for Key Nr. 2 and Property Text

3) Access the resources 

Use String-Resources from Code

var rl = new ResourceLoader();
var value1 = rl.GetString("key1");
var value2 = rl.GetString("key2/text");

Use String-Resources in XAML

<TextBlock x:Uid="key2" Text="Default Text" />

 4) Support for different languages

  • Add a Resource-Folder (e.g. "strings")
  • Add Folders for each language (e.g. "en", "de", "it")
  • Add a Resources.resw-File into this folders

5) Multiple Files

To access strings from the file Errors.resw use this

new ResourceLoader("Errors")

and

<TextBlock x:Uid="/Errors/key2" Text="Default Text" />

 6) Resources in DLL-Projects

If you want to use a DLL project specific Resources.resw you must specify this

var rl = new ResourceLoader("Dll.Project.Namespace/Resources);

"Dll.Project.Namespace" must be replaced with the real DLL namespace.

Kommentare sind geschlossen

Tags