在运行时改变应用程序的语言上即时 [英] Change App language at RunTime on-the-fly

查看:388
本文介绍了在运行时改变应用程序的语言上即时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发一个地铁的应用程序中,用户可以在运行时改变当前的语言和加载必须对新的语言更新他们的文本中的所有自定义控件。问题是,当我使用下面的代码,应用程序语言的变化而变化的语言,但是当我重新启动我的应用程序只会更新文本,因为网页和那些已经呈现被缓存的控制。

I'm currently developing a metro app in which the user can change current language at runtime and all the custom controls that are loaded must update their text regarding to the new language. Problem is that when I change the language using the following code, the app language changes but it will only update text when I restart my app because the pages and controls that are already rendered are cached.

LocalizationManager.UICulture = new System.Globalization.CultureInfo((string)((ComboBoxItem)e.AddedItems[0]).Tag);
Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = ((ComboBoxItem)e.AddedItems[0]).Tag as String;



我应该怎么做强制更新在运行时的所有自定义控件的文本,无需重新启动我的应用程序?

What should I do to force updating text of all custom controls at runtime without restarting my app?

推荐答案

使用这样的:

var NewLanguage = (string)((ComboBoxItem)e.AddedItems[0]).Tag;

Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = NewLanguage;

Windows.ApplicationModel.Resources.Core.ResourceContext.GetForViewIndependentUse().Reset();
//Windows.ApplicationModel.Resources.Core.ResourceContext.GetForCurrentView().Reset();

Windows.ApplicationModel.Resources.Core.ResourceManager.Current.DefaultContext.Reset();



,然后重新加载页面,使用导航方式:

and then reload your Page, using Navigate method:

if (Frame != null)
    Frame.Navigate(typeof(MyPage));

这篇关于在运行时改变应用程序的语言上即时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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