Reputation: 8448
I have a WPF application that I want it to be two languages. I duplicated my Resources.resx
and built my two languages like this:
So when I first load my MainApplication
I do this:
Properties.Resources.Culture = new CultureInfo("es-ES");
before the
InitializeComponent();
So everything is loaded in the desired language. Now I want to go the obvious step further, and I designed a Select language
on my application:
Any idea on how to reload the interface for the different languages at execution time?
EDIT:
I found this link, and seems to work. But I have a problem. When I try to find the Resources x:key
it launches an error... It says ResourceReferenceKeyNotFoundException
. Go here to check my mistake.
Upvotes: 1
Views: 7547
Reputation: 153
You want to change the culture for the UI thread, this should work:
var culture = new CultureInfo("en-US");
Thread.CurrentThread.CurrentCulture = culture;
Thread.CurrentThread.CurrentUICulture = culture;
FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));
Upvotes: 3