在UWP中更改语言不会更改系统功能语言-仅在应用重启时 [英] Changing language in UWP doesn't change system features language - only on app restart

查看:310
本文介绍了在UWP中更改语言不会更改系统功能语言-仅在应用重启时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UWP应用程序.

I have a UWP application.

而且我需要即时更改语言环境,因此我需要使用此语言来进行语言更改:

And i have a need to change locale on the fly, so i have this for language changing:

Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = language.FourDigitCode;
ResourceContext.GetForViewIndependentUse().Reset();
ResourceContext.GetForCurrentView();

但是存在一个问题,即系统功能语言不会切换(仅在应用程序重新启动之后),我该如何解决?

这里是一个例子:

现在我运行这段代码:

Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = "lv-LV";
ResourceContext.GetForViewIndependentUse().Reset();
ResourceContext.GetForCurrentView();

用户界面已本地化,但系统功能仍未本地化:

The UI gets localized, but system features still remain unlocalized:

但是当我重新启动应用程序时,一切正常:

But when i restart the app, all is OK:

有什么想法我该如何解决?

推荐答案

恐怕对此没有解决方法,您所看到的是设计使然.引用 PrimaryLanguageOverride 属性:

I'm afraid there is no fix for this and what you've seen is by design. Ref Remarks of PrimaryLanguageOverride property:

设置 PrimaryLanguageOverride ,这会立即反映在语言中财产.但是,此更改可能不会立即对应用程序UI中加载的资源生效.为确保应用程序对此类更改做出响应,您可以收听 QualifierValues 属性,并采取可能需要的任何操作来重新加载资源.这些要求可能会因应用程序使用的UI框架而异,并且可能需要重新启动应用程序.

When you set the PrimaryLanguageOverride, this is immediately reflected in the Languages property. However, this change may not take effect immediately on resources loaded in the app UI. To make sure the app responds to such changes, you can listen to the QualifierValues property on a default resource context and take whatever actions may be needed to reload resources. Those requirements may vary depending on the UI framework used by the app, and it may be necessary to restart the app.

对于您的情况,需要重新启动.我建议您可以添加提示以告诉用户重新启动该应用程序,还可以添加一个按钮来关闭该应用程序,如新闻应用程序中所使用的一样.
要关闭该应用程序,我们可以调用应用程序.Exit 方法如下.

For your scenario, a restart is needed. I'd suggest that you can add a tip to tell users to restart the app and also a button to close the app like what used in News App.
And to close the app, we can call Application.Exit method like the following.

Application.Current.Exit();

这篇关于在UWP中更改语言不会更改系统功能语言-仅在应用重启时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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