Each time we build an app, the Resource Management System creates a Package Resource Index (PRI) file that is packaged with the app and helps to resolve resources at run time.

More info about the Management System and PRI files can be found here: Resource Management System.

The PRI file contains all the Named Resource collected at build time. The PRI file is just a table of named resources and references to the resource file inside the app package.

The interesting point is that named resource can have multiple values, depending on the qualified variants. At runtime the Resource Manager will resolve to the appropriate resource file based on the runtime ResourceContext.

Qualified variant can be:

  • language (can be abbreviated with “lang” keyword when used on a resource filename and even omitted when used as a folder name)
  • scale
  • contrast
  • homeregion
  • targetsize
  • layoutdir
  • config
  • altform
  • DXFeatureLevel (can be abbreviated with “DXFL” keyword)

More on this can be found here: How to name resources using qualifiers (XAML).

As an example, we can have a single Named Resource image (i.e. “MyImage”) with different jpeg files based on language, scale and contrast.

But where do we need to put those jpeg files on our Visual studio project, and how do we need to name them to ensure the above mechanism will work?

The easiest way is to put all the resources files in the project folder or whatever folder you like inside the project folder (i.e. /Assets/Images) and insert the qualified variants directly on the name of the resource:

Or use qualified variant folders or a mix of the two:

It’s worth noting that you can put this folder tree inside other folders, or you can even interleave qualified variant folders with other folders:

So, as an example, the resource file /assets/Localized Images/it/contrast-high/MyImage.scale-100.jpg is equivalent to the resource file MyImage.lang-it.contrast-high.scale-100.jpg .

The order of the qualified variants is irrelevant, i.e. MyImage.lang-it.contrast-high.scale-100.jpg is equivalent to MyImage.scale-100.lang-it.contrast-high.jpg or any other permutation.

Now that I’ve explained resource management, let’s look at the .resw file type and the XAML x:Uid.

Despite the difference of file extension, the .resw file format is identical to the .resx file format, except that .resw files may contain only strings and file paths.

The Visual Studio offer an easy editing of the file content:

These values can be directly used from the XAML code:

<TextBlock x:Uid=”MyTextBlok” Text=”This text will be shown at design time” />

Where the text property of the TextBox control with a x:Uid of “MyTextBox” at runtime will be set to the value of the resource element with a name corresponding to the join of the Uid value, a dot, and the propriety name:

Please note that we still need to write something in the XAML text propriety to see it at design time.

It is also possible to read these values from code, usually on a ViewModel, bounded to some UI XAML element.

Please check How to load string resources (XAML) to find more info on this subject.

That’s all folks! Happy coding. J

 

Back To the Future: Windows Batch Scripting & ASP.NET vNext
Xamarin XAML Vs Microsoft XAML – The devil is in the details

FEEDBACK