Nasıl yapılır: Yerelleştirilebilir Dize Kaynaklarını Yönetmek için ResourceDictionary Kullanma
Bu örnekte, yerelleştirilebilir dize ResourceDictionary kaynaklarını yerelleştirilebilir (WPF) uygulamaları için Windows Presentation Foundation için nasıl kullanacağız?
Yerelleştirilebilir dize kaynaklarını yönetmek için ResourceDictionary kullanmak için
Yerelleştirmek ResourceDictionary istediğiniz dizeleri içeren bir oluşturun. Aşağıdaki kodda bir örnek gösterilmektedir.
<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>Bu kod, bir dize kaynağı
localizedMessageolan , türünde bir dize kaynağını StringSystem mscorlib.dll.Aşağıdaki ResourceDictionary kodu kullanarak uygulamasını ekleyin.
<Application.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="StringResources.xaml" /> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Application.Resources>Biçimlendirmeden dize kaynağını aşağıdaki gibi Extensible Application Markup Language (XAML) kullanarak kullanın.
<!-- Declarative use of string resource from StringResources.xaml resource dictionary --> <TextBox DockPanel.Dock="Top" Text="{StaticResource localizedMessage}" />Aşağıdakine benzer bir kod kullanarak arka koddan dize kaynağını kullanın.
// 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)Uygulamayı yerelleştirin. Daha fazla bilgi için bkz. Bir Uygulamayı Yerelleştirme.