String resources in Windows Store Apps

Microsoft technologies are changing constantly and without pause. This is good for us (developers), it keeps us busy 🙂

Resources in .Net always were files with .resx extension and easily usable from code through static class that is not available in Windows Store Apps. Why? I don’t know.

In Windows Store Apps exists files with resw extension. In this file you can put string resources only, remember in resx you could put any kind of resources (files, string, audio, images)

Luckily, using in XAML is easier now. Look an example:


<TextBlock x:Uid="/Errors/AlreadyRegistered"></TextBlock>

Where:

Errros : is the name of resw file. Unique in all solution. Complete path isn’t possible

AlreadyRegisteres : Is the string resource in resw file

In the other hand, using in code is more difficult or maybe less intuitive. Look an example:


var res =  Windows.ApplicationModel.ResourceLoader('Errors');
res.GetString('AlreadyRegistered');

Loading strings from libraries, controls, or software development kits (SDKs).

However, loading resources from another library seems easier in Windows Store than old platforms. Oh my gosh, I said old? 🙂

ResourceLoader R = new Windows.ApplicationModel.Resources.ResourceLoader(“ContosoControl/Resources”);
R.getString(“loadingStr”); // which came from ContosoControl’s Resources.resw

Where :

ContosoControl : External library name

Resources : resw file name

loadingStr : string resource

More information:

How to load string resources (Windows Store apps using C#/VB/C++ and XAML)

 

 

Anuncis

Deixa un comentari

Fill in your details below or click an icon to log in:

WordPress.com Logo

Esteu comentant fent servir el compte WordPress.com. Log Out / Canvia )

Twitter picture

Esteu comentant fent servir el compte Twitter. Log Out / Canvia )

Facebook photo

Esteu comentant fent servir el compte Facebook. Log Out / Canvia )

Google+ photo

Esteu comentant fent servir el compte Google+. Log Out / Canvia )

Connecting to %s