This documentation is archived and is not being maintained.

How to: Use a ResourceDictionary to Manage Localizable String Resources

This example shows how to use a ResourceDictionary to package localizable string resources for Windows Presentation Foundation (WPF) applications.

To use a ResourceDictionary to manage localizable string resources

  1. Create a ResourceDictionary that contains the strings you would like to localize. The following code shows an example.

      <!-- String resource that can be localized -->
      <system:String x:Key="localizedMessage">en-US Message</system:String>

    This code defines a string resource, localizedMessage, of type String, from the System namespace in mscorlib.dll.

  2. Add the ResourceDictionary to your application, using the following code.

          <ResourceDictionary Source="StringResources.xaml" />
  3. Use the string resource from markup, using Extensible Application Markup Language (XAML) like the following.

    <!-- Declarative use of string resource from StringResources.xaml resource dictionary -->
    <TextBox DockPanel.Dock="Top" Text="{StaticResource localizedMessage}" />
  4. Use the string resource from code-behind, using code like the following.

    // Programmatic use of string resource from StringResources.xaml resource dictionary 
    string localizedMessage = (string)Application.Current.FindResource("localizedMessage");
  5. Localize the application. For more information, see How to: Localize an Application.

For the complete source code for this example, see Implementing Localizable String Resources in XAML Sample.