I want to create a Software, where the User can choose between several Languages.
As a start i want to learn how to handle Internationalization, since i have never
If you created two ResourceDictionary files you can binding by DynamicResource
.
Example:
First resource file (Lang.en-US.xaml):
Username:
Password:
Close
Login
Second resource file (Lang.pl-PL.xaml):
Login:
Hasło:
Zamknij
Zaloguj
Set default language in Application resources:
Let's say that we have ComboBox like below:
Code-behind SelectionChanged:
private void cbLang_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
ResourceDictionary dict = new ResourceDictionary();
switch (((sender as ComboBox).SelectedItem as ComboBoxItem).Tag.ToString())
{
case "en-US":
dict.Source = new Uri("Lang.en-US.xaml", UriKind.Relative);
break;
case "pl-PL":
dict.Source = new Uri("Lang.pl-PL.xaml", UriKind.Relative);
break;
default:
break;
}
this.Resources.MergedDictionaries.Add(dict);
}
And you can binding like this: