How to change message dialog text font at runtime in uwp?

298 views Asked by At

I am developping a kiosk app for people come from diffrent countries, UI language should be changed at runtime.

ApplicationLanguages.PrimaryLanguageOverride can change the text and font shown in pages, but no effect for content in a message dialog, dialogs always shown in a font for the default language.

Some language should not be shown in a font for another language, just like Chinese text should not be shown in a Japanese font.

Is there a way to change the dialog font at runtime, just like ApplicationLanguages.PrimaryLanguageOverride property for pages?

1

There are 1 answers

0
Jet  Chopper On

My solution was to create a Class Language, define there a string Lcid (you may google what is LCID) and List of strings Texts.

Create a static method that will return you all your texts in different languages and fill it:

public class Language
{
    public string Lcid { get; set; }
    public List<string> Texts { get; set; }

    public static List<Language> GetLanguages()
    {
        return new List<Language>
        {
            new Language
            {
                Lcid = "uk",
                Texts = new List<string>
                {
                    "Привіт",
                    "Бувай"
                }
            },
            new Language
            {
                Lcid = "en",
                Texts = new List<string>
                {
                    "Hello",
                    "Bye"
                }
            },
        };
    }
}

In your UserControl:

    private readonly List<Language> _languages = Language.GetLanguages();
    private List<string> _currentLanguageTexts = new List<string>();

Now you may switch your languages by comparing current LCID and set Texts to the _currentLanguageTexts that should be x:Binded in your XAML.