Converting to Windows 8 from Windows Phone | Localization of your application (9 of 12)

I don’t think I need to stress how important it is to place all of your texts (as in language specific texts visible to the end user) in the same place. To look around in your code and XAML after strings that may be duplicated through the application makes us sad developers. Even if you from start only support one language (and don’t plan to support any other) you can save a lot of time by adding all of your text in a resource file from start.

We, naturally, went with resource files when implementing Reseguidens sista-minuten application. We also chose to read from the resource file in our view models and then databind to the view. We did this because it is simpler to add dynamic data with string.Format(…) in the view model.

In this post we’ll explain how we used resource files when implementing the Windows Phone application, and how we changed it for Windows 8.

This post is a part in a series – you can find the full index here.

New file type

First of all, before I say anything else, I would like to point out that the resx file type, that we are used to, has been switched to a resw file type in Windows 8. This means that you cannot directly reuse your old resource files.

This is really no problem. You simply select all in your old resx file and copy it into your new resw file.

Databind texts from the view model

Pro – as we mentioned earlier, is that you easily can format the text when mixing it up with data. Con – you need to write a lot of extra code. Below are some code that we just cut from a view model in the Windows Phone application. Our resource file is named AppResources.

public string DateToTitle { get {
  return AppResources.DetailPivot_DateToTitle; } }
public string TripLengthTitle { get {
  return AppResources.DetailPivot_TripLengthTitle; } }
public string InfoTitle { get {
  return AppResources.DetailPivot_InfoTitle; } }

So, this won’t compile in Windows 8. The handling of resource files has changed. If we want to bind the text resources in a similar manner in Windows 8 we first need to initiate a ResourceLoader.

var resourceLoader = new ResourceLoader("AppResources");

Then to get the values we write.

public string DateToTitle { get {
  return _resources.GetString("DetailPivot_DateToTitle"); } }
public string TripLengthTitle { get {
  return _resources.GetString("DetailPivot_TripLengthTitle"); } }
public string InfoTitle { get {
  return _resources.GetString("DetailPivot_InfoTitle"); }

So gone is the type safe static methods, instead we have strings (o_O). I don’t know why or how this decision was made, but in either case it doesn’t feel right to fetch the texts by string keys in the view model anymore. Not at all.

Bind directly to resource files in the view

This is the second option. This option is of course available in Windows Phone as well. But then you would preferably do it via a proxy and yes, it becomes quite messy for a functionality that really should be very simple.

How does it work in Windows 8 then? Well – better.

In Windows 8 you got a new convention based way to bind resource keys to a view. Let us look at an example.

Note that the only thing specified is the Uid, it will bind to this.


No other code is necessary. The binding is handled by conventions that look at the resource name and the Uid and then match up the ones that fit. Very, very neat.

However you did it on your Windows Phone

You’ll probably end up rewriting some of the code for Windows 8. Luckily, it’s really simple to copy texts from an old resx file to a new resw file. On a personal note – we think that the convention based binding in Windows 8 feels much more modern and slick than the bulky old way.

This Post Has One Comment

Leave a Reply