Skip to content

Cheat sheet

Jecho Jekov edited this page Nov 26, 2017 · 3 revisions
Installation

Install the NuGet package for the WPF projects that need to be localized. Alternatively, compile the source code and add reference to the WpfLocalization.dll assembly.

Localized resources

Add localized text, images and other resources to Properties/Resources.resx (C#) or My Project/Resources.resx (VB.NET) (alternatively go to Project -> Properties -> Resources).

Then use resource names with the Loc extension: <SomeElement Property="{Loc [Resource Name]}"/> (see below).

Localize text
<TextBlock Text="{Loc Text_HelloWorld}"/>
Localize an image
<Image Source="{Loc Image_CapitalPhoto}"/>
Localize a binding
<TextBlock Text="{Loc Text_HelloUser, Binding={Binding UserName}}"/>
<TextBlock Text="{Loc StringFormat='{}{0:d}', Binding={Binding BirthDate}}"/>
Set the culture
LocalizationManager.CurrentCulture = CultureInfo.GetCulture("en-US");
LocalizationManager.CurrentUICulture = CultureInfo.GetCulture("en-US");
Set the culture for design-time preview
<Window ... LocalizationScope.UICulture="{CultureInfo en-US}" LocalizationScope.Culture="{CultureInfo en-US}">
Reference a resource file
<Window ... LocalizationScope.ResourceManager="{ResourceManager AssemblyName='SomeAssembly', ResourceFile='SomeAssembly.Properties.SomeResources'}">
<Window ... xmlns:properties="clr-namespace:SomeAssembly.Properties" LocalizationScope.ResourceManager="{ResourceManager Type={x:Type properties:SomeResources}}">
<Window ... LocalizationScope.ResourceManager="{LocalResourceManager SomeResources}">

Clone this wiki locally