mirror of
https://github.com/Stone-Red-Code/docs-desktop.git
synced 2026-09-07 07:56:07 +02:00
* Reset branch for WPF changes * Convert BMP to PNG; fix link-out-of-scope err * Add snippets for WPF... 6794 files!!!! * Add missing snippets * update file updated between migration * Fix paths to include * update breadcrumb and toc * fix index links * fix index links * fix index links * fix markdown
39 lines
2.4 KiB
Markdown
39 lines
2.4 KiB
Markdown
---
|
|
title: "How to: Use a ResourceDictionary to Manage Localizable String Resources"
|
|
ms.date: "03/30/2017"
|
|
dev_langs:
|
|
- "csharp"
|
|
- "vb"
|
|
helpviewer_keywords:
|
|
- "resources [WPF], packaging string resources"
|
|
- "packaging string resources [WPF]"
|
|
- "ResourceDictionary [WPF]"
|
|
- "localization [WPF], packaging string resources"
|
|
ms.assetid: 19e7d9a5-20df-4ad3-b157-fe6515902e5e
|
|
---
|
|
# How to: Use a ResourceDictionary to Manage Localizable String Resources
|
|
This example shows how to use a <xref:System.Windows.ResourceDictionary> to package localizable string resources for Windows Presentation Foundation (WPF) applications.
|
|
|
|
### To use a ResourceDictionary to manage localizable string resources
|
|
|
|
1. Create a <xref:System.Windows.ResourceDictionary> that contains the strings you would like to localize. The following code shows an example.
|
|
|
|
[!code-xaml[StringLocalizationSample#StringResourceDictionary](~/samples/snippets/csharp/VS_Snippets_Wpf/StringLocalizationSample/CSharp/StringResources.xaml#stringresourcedictionary)]
|
|
|
|
This code defines a string resource, `localizedMessage`, of type <xref:System.String>, from the <xref:System> namespace in mscorlib.dll.
|
|
|
|
2. Add the <xref:System.Windows.ResourceDictionary> to your application, using the following code.
|
|
|
|
[!code-xaml[StringLocalizationSample#ReferencingStringResourceDictionary](~/samples/snippets/csharp/VS_Snippets_Wpf/StringLocalizationSample/CSharp/App.xaml#referencingstringresourcedictionary)]
|
|
|
|
3. Use the string resource from markup, using [!INCLUDE[TLA#tla_xaml](../../../includes/tlasharptla-xaml-md.md)] like the following.
|
|
|
|
[!code-xaml[StringLocalizationSample#GetLocalizedResourceFromMarkup](~/samples/snippets/csharp/VS_Snippets_Wpf/StringLocalizationSample/CSharp/MainWindow.xaml#getlocalizedresourcefrommarkup)]
|
|
|
|
4. Use the string resource from code-behind, using code like the following.
|
|
|
|
[!code-csharp[StringLocalizationSample#GetLocalizedResourceFromCode](~/samples/snippets/csharp/VS_Snippets_Wpf/StringLocalizationSample/CSharp/MainWindow.xaml.cs#getlocalizedresourcefromcode)]
|
|
[!code-vb[StringLocalizationSample#GetLocalizedResourceFromCode](~/samples/snippets/visualbasic/VS_Snippets_Wpf/StringLocalizationSample/VisualBasic/MainWindow.xaml.vb#getlocalizedresourcefromcode)]
|
|
|
|
5. Localize the application. For more information, see [Localize an Application](how-to-localize-an-application.md).
|