我使用 MergedDictionaries 和项目的设置在我的项目中编写了一个选择语言选项。问题是语言仅在我的 MainWindow 中成功更改,而在其他 Windows中也没有。我究竟做错了什么?
MainWindow 中的设置语言功能(编辑:MainWindow.cs):
/*set language*/
private void SetLanguageDictionary()
{
ResourceDictionary dict = new ResourceDictionary();
if (Properties.Settings.Default.Language.Equals("en")) //english was set
{
dict.Source = new Uri("\\res\\enDictionary.xaml", UriKind.Relative);
}
else //otherwise - hebrew as default lang.
{
dict.Source = new Uri("\\res\\hebDictionary.xaml", UriKind.Relative);
}
//add required dictionary to the MergedDictionaries
Resources.MergedDictionaries.Add(dict);
}
一个字典的一个小例子[它们是对称设置的,如果重要的话]:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:UI_WPF"
xmlns:system="clr-namespace:System;assembly=mscorlib">
<system:String x:Key="employees">Employees</system:String>
<system:String x:Key="employers">Employers</system:String>
<system:String x:Key="contracts">Contracts</system:String> </ResourceDictionary>