如何更改ComboBox Items文本翻译?我有组合框,可在其中选择语言。应用程序语言正在更改,但无法将复选框项目的文本更改为所选语言。
我的 xaml :
<ComboBox HorizontalAlignment="Left" Margin="10,0,0,0" VerticalAlignment="Center" Width="120" ItemsSource="{Binding Path=Languages}" SelectedItem="{Binding Path=SLanguage, Mode=TwoWay}" DisplayMemberPath="LanguageName" IsTabStop="False"/>
我的 VM :
private ObservableCollection<LanguageSelector> _languages;
public ObservableCollection<LanguageSelector> Languages
{
get { return _languages; }
set
{
_languages = value;
}
}
private LanguageSelector _slanguage;
public LanguageSelector SLanguage
{
get { return _slanguage; }
set
{
_slanguage = value;
ChangeSelectedLang();
}
}
private void ChangeSelectedLang()
{
if (SLanguage.Id == 1)
{
CultureInfo.CurrentCulture = new CultureInfo("pl-PL");
SetLanguageDictionary();
}
else
{
CultureInfo.CurrentCulture = new CultureInfo("en-EN");
SetLanguageDictionary();
}
}
private void SetLanguageDictionary()
{
ResourceDictionary dict = new ResourceDictionary();
switch (Thread.CurrentThread.CurrentCulture.ToString())
{
case "pl-PL":
dict.Source = new Uri("..\\Resources\\LanguagePL.xaml", UriKind.Relative);
break;
case "en-EN":
dict.Source = new Uri("..\\Resources\\LanguageEN.xaml", UriKind.Relative);
break;
default:
dict.Source = new Uri("..\\Resources\\Language.xaml", UriKind.Relative);
break;
}
{
Application.Current.Resources.MergedDictionaries.Add(dict);
}
}
public void FillCombo()
{
Languages = new ObservableCollection<LanguageSelector>()
{new LanguageSelector(){Id=1, LanguageName=Application.Current.FindResource("pl-PL") as string }
,new LanguageSelector(){Id=2, LanguageName=Application.Current.FindResource("en-EN") as string }
};
this.SLanguage = Languages.FirstOrDefault();
}
在我的恐怖中,我有:
<system:String x:Key="pl-PL">Polski</system:String>
<system:String x:Key="en-EN">Angielski</system:String>
我要为EN ex更改组合框项目文本时将其切换为所选语言。波兰斯基到波兰