Problem: Can we load a resource file without changing the language from device settings?
Solution:
public void SetLang(string lang)
{
App.RootFrame.Language = XmlLanguage.GetLanguage(AppResources.ResourceLanguage);
Thread.CurrentThread.CurrentCulture = new CultureInfo(lang);
Thread.CurrentThread.CurrentUICulture = new CultureInfo(lang);
NavigationService.Navigate(new Uri(string.Format("/MainPage.xaml?random={0}", Guid.NewGuid()), UriKind.Relative));
NavigationService.RemoveBackEntry();
Let's talk a bit! This method changes current culture settings and then redirects to the current page with a unique querystring. If we hadn't written the querystring then the culture would be the default culture, that is English in our app. By using this code, we ensure that each culture has a unique identifier when called and that prevents complexity.
SetLang("en-US");
SetLang("fr-FR");
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: