我有一个多语言应用程序,允许用户使用下拉菜单切换语言。它工作正常,但切换语言时速度太慢,因为我需要重新导航到当前帧。这是因为我需要重新加载我的产品(这需要一些时间)。
这是我的代码:
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 中是否有任何等价物?或者有没有更好的方法来解决我的问题?
谢谢
最佳答案
我用过 this pattern from the documentation使用 this sample通知我的数据发生变化。如果我没猜错,你想在它改变时通知 xaml 元素的内容(例如文本)。然后你需要使用绑定(bind)。
希望有帮助!
关于c# - UWP 如何在不重新导航的情况下刷新文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43293722/