Localizing WPF controls with ResX files

Situation

You want to localize a WPF control.

Problem

Books on WPF recommend to use Microsofts LocBaml.exe, which is actually just a sample that is, of course, not integrated anywhere.

Solution

Localize the WPF control using ResX files.

  1. create the ResX files
  2. set the scope of the ResX files to public
  3. add the Properties namespace to your XAML
    xmlns:res="clr-namespace:YourNamespace.Properties"
  4. use static binding to define the value
    <TextBlock Text="{x:Static res:YourResource.YourResourceProperty}"/>

Sources

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.