I have a WPF application that supports multiple languages.
I saw this answer to the question Best way to implement multi-language (using .resx files) here on Stackoverflow. Everything works great except that the language doesn't change at runtime.
I have seen this answer to the question How to change the CurrentUICulture at runtime here on Stackoverflow but unfortunately his answer does not help me because the link he posted in his solution does not work.
I saw a lot of articles on google but no success.
A little attempt of mine (.cs):
private void EventSetter_OnHandler(object sender, MouseButtonEventArgs e)
{
string item = ((ComboBoxItem)sender).Content.ToString();
switch (item)
{
case "English":
Console.WriteLine("English");
System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-GB");
System.Threading.Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("en-GB");
Product.Language.Resources.Culture = new System.Globalization.CultureInfo("en-GB");
break;
case "German":
Product.Language.Resources.Culture = new System.Globalization.CultureInfo("de-DE");
Console.WriteLine("German");
break;
default:
Console.WriteLine("none");
break;
}
}
XAML:
<Grid>
<StackPanel>
<Label x:Name="LabelHeader1" Content="{x:Static language1:Resources.LanguageTL}" />
<Label x:Name="LabelHeader2" Content="{x:Static language1:Resources.HomeTL}" />
<Label x:Name="LabelHeader3" Content="{x:Static language1:Resources.SkyTL}" />
<ComboBox x:Name="Languages">
<ComboBoxItem IsSelected="True">English</ComboBoxItem>
<ComboBoxItem>German</ComboBoxItem>
<ComboBox.ItemContainerStyle>
<Style>
<EventSetter Event="ComboBox.PreviewMouseDown" Handler="EventSetter_OnHandler" />
</Style>
</ComboBox.ItemContainerStyle>
</ComboBox>
</StackPanel>
</Grid>
The keys are saved in .resx
files:
And thanks for the help