Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
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
Create a ResourceDictionary file in the root of your project named StringResources.xaml that contains the strings you would like to localize. The following code shows an example.
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:system="clr-namespace:System;assembly=mscorlib"> <!-- String resource that can be localized --> <system:String x:Key="localizedMessage">en-US Message</system:String> </ResourceDictionary>
This code defines a string resource,
localizedMessage
, of type String, from the System namespace in mscorlib.dll.Add the ResourceDictionary to your application, using the following code.
<Application.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="StringResources.xaml" /> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Application.Resources>
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}" />
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"); MessageBox.Show(localizedMessage);
' Programmatic use of string resource from StringResources.xaml resource dictionary Dim localizedMessage As String = CStr(Application.Current.FindResource("localizedMessage")) MessageBox.Show(localizedMessage)
Localize the application. For more information, see Localize an Application.
.NET Desktop feedback