UWP MVVM: refresh page after change of language

懵懂的女人 提交于 2020-01-05 07:57:45

问题


I have some code in my view model which changes the application language, which then changes the text on some of the controls.

This is the DashboardViewModel, which the Dashboard Page's data context is set to:

ApplicationLanguages.PrimaryLanguageOverride = languageCode;
ResourceContext.GetForCurrentView().Reset();
ResourceContext.GetForViewIndependentUse().Reset();
NavigationService.Navigate(typeof(DashboardPage));

With NavigationService.Navigate(typeof(DashboardPage)); I tried to force the page to refresh, with no success. How would I do this?


回答1:


this line works very well for me.

 await Task.Delay(100);
 Frame.Navigate(this.GetType());



回答2:


NavigationService.Navigate() is not doing anything if you're trying to navigate to the same page.

On workaround is to add a parameter to your navigation request to force it.

NavigationService.Navigate(typeof(DashboardPage), "force refresh after language change");



回答3:


I have used an approach similar to @Vincent, but using DateTime.Now.Ticks as the parameter. This ensures that the value of the parameter is going to be different, which triggers the refresh.

NavigationService.Navigate(typeof(DashboardPage), DateTime.Now.Ticks);


来源:https://stackoverflow.com/questions/47792071/uwp-mvvm-refresh-page-after-change-of-language

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!