public partial class App : Application
{
public App()
{
switch (Thread.CurrentThread.CurrentCulture.ToString())
{
case "de-DE":
var German = new Uri("..\\GlobalString\\Dictionary_de-DE.xaml", UriKind.RelativeOrAbsolute);
Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary() { Source = German });
break;
case "it-IT":
var Italy = new Uri("..\\GlobalString\\Dictionary_it-IT.xaml", UriKind.RelativeOrAbsolute);
Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary() { Source = Italy });
break;
case "es-ES":
var Spanish = new Uri("..\\GlobalString\\Dictionary_es-ES.xaml", UriKind.RelativeOrAbsolute);
Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary() { Source = Spanish });
break;
case "fr-FR":
var France = new Uri("..\\GlobalString\\Dictionary_fr-FR.xaml", UriKind.RelativeOrAbsolute);
Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary() { Source = France });
break;
default:
var English = new Uri("..\\GlobalString\\Dictionary_de-DE.xaml", UriKind.RelativeOrAbsolute);
Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary() { Source = English });
break;
}
}
}
首先我合并了所有字典,然后我尝试从字典中动态获取值,如下所示。但它显示错误(未找到'MyString'资源)。
private void Window_Loaded(object sender, RoutedEventArgs e)
{
string StringFromDictionary= Application.Current.FindResource("MyString");
}