Windows 8 Store App and Universal App Multilanguage support

To realize multilanguage app now in Window Store app, Windows Phone 8.1 and universal app the resources are changed.

This Microsoft post show how to use resource:

as you can see It is necessary set the attribute x:Uid in the target control like this:

In resource file .resw add this key:

This key is composed by [Control Uid].[Property]

In design time the resource file will not be used so the text displayed is the property “Text” or “Header”; only at runtime the right resource text will be applyed.

But how can we use only one string/resource and share it with many controls and many property like TextBlock.Text , Button.Content, Hub.Header ecc??
The answer coming from Windows Phone 7.

Set in the resource file a key like “MyKey”

Create this class:

public class LocalizedStrings
    private static ResourceLoader _localizedResources = new ResourceLoader();

    public ResourceLoader LocalizedResources { get { return _localizedResources; } }

    private string GetVal(string key)
        return LocalizedResources.GetString(key);

    public string this[string key]
            return GetVal(key);

Use it in every place you need.

By code:
new LocalizedStrings()[“MyKey”]

By Xaml:

Create an instance in app.xaml file:

    <local:LocalizedStrings x:Key="LocalizedStrings" />

Use it in your xaml page:

<HubSection Header="{Binding [MyKey], Source={StaticResource LocalizedStrings}}">
<Button Content="{Binding [MyKey], Source={StaticResource LocalizedStrings}}" />
<TextBlock Text="{Binding [MyKey], Source={StaticResource LocalizedStrings}}" />

This permit to specify only on key/value entry and reference it many times.
This is very similar to wp8/wp7.

Informazioni su Andrea Regoli

Project Manager .Net Developer WPF WP7 Asp.Net c# javascript ajax SQL sharepoint
Questa voce è stata pubblicata in c#, Silverlight, Store Apps, Windows 8, WP8, xaml e contrassegnata con , , , . Contrassegna il permalink.


Inserisci i tuoi dati qui sotto o clicca su un'icona per effettuare l'accesso:

Logo di

Stai commentando usando il tuo account Chiudi sessione /  Modifica )

Google photo

Stai commentando usando il tuo account Google. Chiudi sessione /  Modifica )

Foto Twitter

Stai commentando usando il tuo account Twitter. Chiudi sessione /  Modifica )

Foto di Facebook

Stai commentando usando il tuo account Facebook. Chiudi sessione /  Modifica )

Connessione a %s...

Questo sito utilizza Akismet per ridurre lo spam. Scopri come vengono elaborati i dati derivati dai commenti.