UWP如何刷新文本而无需重新导航

问题描述 投票:1回答:1

我有一个多语言应用程序,允许用户使用下拉菜单切换语言。它运行正常,但切换语言时速度太慢,因为我需要重新导航到当前帧。这是因为我需要重新加载我的产品(这需要一些时间)。

这是我的代码:

 var culture = new System.Globalization.CultureInfo(sLang);
 Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = culture.Name;
 Windows.ApplicationModel.Resources.Core.ResourceContext.GetForCurrentView().Reset();
 Windows.ApplicationModel.Resources.Core.ResourceContext.GetForViewIndependentUse().Reset();

 Frame.Navigate(Frame.CurrentSourcePageType);  //I want to avoid this as calling this will re-initialize my page - which in turn re-load my products

我的问题是,有没有办法强制所有组件使用x:Uid从资源文件(例如Strings / en-US / Resources.resw)重新加载而不调用Frame.Navigate()?

在WinForm中,我可以做类似的事情:

System.Resources.ResourceManager rm = new System.Resources.ResourceManager(typeof(MainForm));
foreach (Control ctl in this.Controls)
{
    rm.ApplyResources(ctl, ctl.Name);
}

UWP中有没有相应的内容?或者有更好的方法来解决我的问题吗?

谢谢

c# uwp win-universal-app multilingual
1个回答
1
投票

我使用this pattern from the documentation,它使用this sample来通知我数据的变化。如果我没有错,你想要在更改时通知xaml元素的内容(例如Text)。然后你需要使用绑定。

希望有所帮助!

© www.soinside.com 2019 - 2024. All rights reserved.