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?
this line works very well for me.
await Task.Delay(100);
Frame.Navigate(this.GetType());
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");
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);