Given the limitations of XAML on the Windows Phone operating system, in order to use
.resx files to localize your app you must complete a few additional steps.
1 - Prepare Your .resx File
In Visual Studio, create a resource file (for example
Strings.resx), open it and make sure the
Access Modifier setting is set to
Public.
2 - Create a Proxy Class
Because in WP7 XAML does not support access to embedded resource files, you must first create a simple class that acts as a
proxy.
public class LocalizedStrings {
public LocalizedStrings() { }
// Strings is the name of the resource file created before
private static YourNamespace.Strings localizedResources = new Namespace.Strings();
// Keep the name of this property short, to make code less verbose
public YourNamespace.Strings LR {
get { return localizedResources; }
}
}3 - Register The Proxy Class As Static Resource
Open the
App.xaml file and add the following XML, which will allow you to use your resources directly in XAML files.
<Application.Resources>
<local:LocalizedStrings xmlns:local="clr-namespace:YourNamespace" x:Key="LR" />
</Application.Resources>4 - Use Localized Resources in XAML Code
You can now easily use localized resources right from XAML.
<ListBoxItem Content="{Binding Path=LR.MyContent, Source={StaticResource LR}}" />Further Reading
You can find additional resources on this
detailed tutorial on MSDN, as well as a
step-by-step video.