Localization on WP8.1

July 1, 2015 · Dev App WP8

As far as I understood - and for whatever reason MSDN is quite silent about this - in the switch between WP8 and WP8.1, the localization API of Windows RT changed. After fighting with it (again) today for a while, I decided to put this here for good.

WPF Binding

In WPF, you have to rely on the x:Uid Tag:

<TextBox x:Uid="UriTextBox" x:Name="UriTextBox" Grid.Row="1" Text=""></TextBox>

In your Resource File

That's the trick. In your resource files, you now need to relate to the Uid + the name of the field that you want to fillup. In our case UriTextBox.Text.

In your C# Code

From your C# code, you now get the different localized strings via the ResourceLoader:

ResourceLoader resourceLoader = ResourceLoader.GetForCurrentView("Resources");

Field Gotcha

If you... per chance... don't use the correct property in your resx File, you will get that kind of super useful errors:

Localization Error

In this case for instance, I tried to set the text of a button via buttonUid.Label instead of buttonUid.Content. Yep, you have to pay close attention to the type of the objects you are using. A Bottom Bar Button (in WP8.1) needs a buttonUid.Label, a normal XAML Button a buttonUid.Content. Really practical...

Comments powered by Disqus