C#更改应用编程语言实时UWP [英] C# change app language programmatically UWP realtime

查看:328
本文介绍了C#更改应用编程语言实时UWP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我为每种语言字符串资源的应用程序分开存放,并显示不同类型的语言环境中。我想更改应用程序设置的语言。我怎么知道,经过语言选择立即在用户界面中应用它?

In my application for each language string resources are stored separately and are displayed depending of type of language environment. I want to change the language in the application settings. How do I realize that after the language selection instantly apply it in the user interface?

推荐答案

我们可以使用的 ApplicationLanguages.PrimaryLanguageOverride 没有重新启动应用程序在运行时更改语言

We can use ApplicationLanguages.PrimaryLanguageOverride to change the language during runtime without restart the app.

例如:我有两种语言的支持。恩和FR 。本地化的消息将在TextBlock中显示出来。

For example: I have two languages supported "en" and "fr", localized message will show up in textblock.


  1. 添加使用Windows.Globalization;

  1. Add using Windows.Globalization;

从EN到FR由

ApplicationLanguages.PrimaryLanguageOverride = "fr";


  • 重新定位到当前页面刷新UI。

  • Re-navigate to the current page to refresh the UI.

    Frame.Navigate(this.GetType());
    


  • 请注意,你需要比较PrimaryLanguageOverride与制度文化来设置下一次应用程序启动的语言,因为PrimaryLanguageOverride设置依然存在。如果您启用页面缓存,当您在运行应用不同的语言,你需要通过设置来清除缓存 Frame.CacheSize = 0; 第一然后将其设置回

    Note that, you need to compare the PrimaryLanguageOverride with the system culture to set the language for next app launch, because the PrimaryLanguageOverride setting is persisted. And if you have page cache enabled, when you apply a different language on the fly, you need to clear the cache by setting Frame.CacheSize = 0; first then set it back.

    这篇关于C#更改应用编程语言实时UWP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆