【发布时间】:2017-06-14 22:21:59
【问题描述】:
我使用 MergedDictionaries 和项目设置在我的项目中编写了选择语言选项。问题是语言仅在我的 MainWindow 中成功更改,而在其他 Windows 中也没有。我做错了什么?
在 MainWindow 中设置语言函数(edit: 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>
【问题讨论】:
-
没有足够的信息,如果没有添加字典是无法使用的。这意味着您正在合并导致此问题的英语词典。
标签: c# .net wpf dictionary mergeddictionaries