implement different language into UWP application from code behind using multilingual

c# windows c#-4.0 uwp uwp-xaml

340 просмотра

1 ответ

3 Репутация автора

Is it possible to implement different language into UWP application from code behind using multilingual toolkit & not by setting the desired language from the settings but instead from the dropdown list of language within the application

Автор: Anup Источник Размещён: 14.07.2016 02:08

Ответы (1)

1 плюс

146 Репутация автора


You don't actually need the Multilingual App Toolkit to modify the language of your app. By default, the app will configure itself based on the settings on the machine, but you can override that by setting the CurrentCulture and/or CurrentUICulture.

Say for instance you had a Combobox that contained "English", "Spanish" and "French"... and your desired behavior is to switch your language to whichever value the user selects. All you'd need to do is hook up the SelectionChanged event. Here's what the code might look like:

   private void ChangeLanguage(object sender, SelectionChangedEventArgs e)
        var newlySelected = e.AddedItems[0] as ComboBoxItem;
        string newLanguage = newlySelected.Content.ToString();
        switch (newLanguage)
            case "English":
                    CultureInfo.CurrentCulture = new CultureInfo("en");
                    CultureInfo.CurrentUICulture = new CultureInfo("en");
            case "Spanish":
                    CultureInfo.CurrentCulture = new CultureInfo("es");
                    CultureInfo.CurrentUICulture = new CultureInfo("es");
            case "French":
                    CultureInfo.CurrentCulture = new CultureInfo("fr");
                    CultureInfo.CurrentUICulture = new CultureInfo("fr");
                    throw new NotImplementedException("Unidentified Language");

Naturally, I'd encourage you to do all the appropriate error checking (Make sure that the cast to ComboBoxItem works, etc...).

Also, remember that you need to set CurrentCulture if you want things like Dates and Times to show in the appropriate locale and use CurrentUICulture if you want to modify which resources your ResourceLoader uses to populate the UI.

Hopefully this should get you up and running!


Автор: Dante Gagne Размещён: 28.07.2016 06:22
Вопросы из категории :