简体   繁体   English

Windows Phone 8.1重新加载/刷新本地化页面

[英]Windows Phone 8.1 Reload/Refresh a page in Localisation

Hi I am working on localisation. 嗨,我正在本地化上。 I have a listbox. 我有一个列表框。 If i change a language in listbox. 如果我在列表框中更改语言。 The whole application has to be changed to that language(Including the current page). 整个应用程序必须更改为该语言(包括当前页面)。

So i obtained that language from listbox and assigned to 所以我从列表框中获得了该语言并分配给

Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = cul;

Question 1: I want to reload/refresh the current page(Ex : Page1)? 问题1:我想重新加载/刷新当前页面(例如:Page1)?

private void LocList_SelectedIndexChanged(object sender, SelectionChangedEventArgs e)
{
    Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = cul;
    var resourceContext = Windows.ApplicationModel.Resources.Core.ResourceContext.GetForCurrentView();
    resourceContext.Reset();
}

This is not working. 这是行不通的。 I also tried 我也试过

private void LocList_SelectedIndexChanged(object sender, SelectionChangedEventArgs e)
{
    Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = cul;
    var manager = Windows.ApplicationModel.Resources.Core.ResourceManager.Current;
    manager.DefaultContext.QualifierValues.MapChanged += QualifierValues_MapChanged;
}

private void QualifierValues_MapChanged(IObservableMap<string, string> sender, IMapChangedEventArgs<string> @event)
{
    ResourceContext.ResetGlobalQualifierValues(); 
    //ResourceManager.Current.DefaultContext.Reset();
}

Question 2 : If i navigate from Page1 to Page2, the changed language is applied in page2. 问题2:如果我从第1页导航到第2页,则更改后的语言将应用于第2页。 But if i come back to Page1, The language change is not applied. 但是,如果我回到第1页,则不会应用语言更改。

Question 2 (Continuation) : I mean If i Navigate from Page2 to Page1. 问题2(续):我的意思是如果我从Page2导航到Page1。 The Page1 constructor is not hitting (If the constructor is hitted the Page initialization will happen to get correct output). Page1构造函数未命中(如果构造函数被命中,则将进行Page初始化以获取正确的输出)。

Guide me if i am doing wrong . 如果我做错了,请引导我。

Thank you People. 谢谢大家。 i got output. 我得到了输出。 The Issue is, the cache was set to Required. 问题是,缓存设置为必需。 Now to fix it i disabled the cache 现在要修复它,我禁用了缓存

  this.NavigationCacheMode = NavigationCacheMode.Disabled;

Previously it was NavigationCacheMode.Required. 以前是NavigationCacheMode.Required。 This is the fix for Question 2 这是问题2的解决方法

Now For Question 1: This code made my page to refresh 现在对于问题1:此代码使我的页面刷新

 var _Frame = Window.Current.Content as Frame;
        _Frame.Navigate(_Frame.Content.GetType());
        _Frame.GoBack(); // remove from BackStack

Ad. 广告。 1 Try to change event type to SelectionChanged on your Listbox ie from LocList_SelectedIndexChanged to LocList_SelectionChanged. 1尝试在列表框上将事件类型更改为SelectionChanged,即从LocList_SelectedIndexChanged更改为LocList_SelectionChanged。

Ad. 广告。 2 Not sure but which version of WP8.1 do you use(silverlight?/win-rt?), navigation is different on both. 2不确定您使用的是哪个版本的WP8.1(silverlight?/ win-rt?),两者的导航方式都不相同。 But as a fast suggestion (suppose win-rt version) don't use GoBack() method, but try to reload language not in constructor but in OnNavigatedTo() method. 但是,作为一个快速建议(假设是win-rt版本),请不要使用GoBack()方法,而应尝试在OnNavigatedTo()方法中而不是在构造函数中重新加载语言。

Anyway try to give more code. 无论如何,请尝试提供更多代码。

Best of luck. 祝你好运。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM