Reputation: 91
I want to change the language at my universal app at runtime-not when restart the app-, I tried this code:
private void ArabicRadioButton_Checked(object sender, RoutedEventArgs e)
{
if (!loaded) return;
var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
localSettings.Values["ArabicSelected"] = true;
Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = "ar-EG";
SettingsHeader.Text = "الاعدادات";
(Window.Current.Content as Frame).Navigate((Window.Current.Content as Frame).Content.GetType());
(Window.Current.Content as Frame).GoBack();
}
private void EnglishRadioButton_Checked(object sender, RoutedEventArgs e)
{
if (!loaded) return;
var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
localSettings.Values["ArabicSelected"] = false;
Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = "en-US";
SettingsHeader.Text = "Settings";
(Window.Current.Content as Frame).Navigate((Window.Current.Content as Frame).Content.GetType());
(Window.Current.Content as Frame).GoBack();
}
the language doesn't change correcty; it changed sometimes and somtimes not. I don't know what is the reason-This proplem is in both Windows 8.1 and Windows phone 8.1-.
Upvotes: 2
Views: 776
Reputation: 108
Try:
var culture = new CultureInfo("en-US");
Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = culture.Name;
CultureInfo.DefaultThreadCurrentCulture = culture;
CultureInfo.DefaultThreadCurrentUICulture = culture;
(Window.Current.Content as Frame).FlowDirection = Windows.UI.Xaml.FlowDirection.LeftToRight;
var loader = new Windows.ApplicationModel.Resources.ResourceLoader();
Also, set flow direction for ar-EG as:
(Window.Current.Content as Frame).FlowDirection = Windows.UI.Xaml.FlowDirection.RighttoLeft;
For en-us:
(Window.Current.Content as Frame).FlowDirection = Windows.UI.Xaml.FlowDirection.LeftToRight;
Upvotes: 1