How to remove a specific page from Navigation cache in Windows Phone 8.1 RT?

亡梦爱人 提交于 2019-12-11 10:26:52

问题


I have set NavigationCacheMode to Required in some pages of my WP 8.1 XAML app. How can I remove a specific page from that? This is not Navigation stack.


回答1:


If a page has NavigationCacheMode set to Required, there is currently no way to remove it explicitly.

If you use Enabled, you can reset the cache using the cache mode:

private void ResetPageCache()
{
    var cacheSize = ((Frame) Parent).CacheSize;
    ((Frame) Parent).CacheSize = 0;
    ((Frame) Parent).CacheSize = cacheSize;
}



回答2:


I couldn't find a way to remove the cache however I managed to get around it by simply setting NavigationCacheMode to Disabled when I click the refresh button in my application.

So when the page reloads it is then set back to required, works a treat for me!

private void refresh_Click(object sender, RoutedEventArgs e)
        {
            this.NavigationCacheMode = NavigationCacheMode.Disabled;
            Refresh.IsEnabled = false;
            switch (flipView.SelectedIndex)
            {
                case 0:
                    ApplicationData.Current.RoamingSettings.Values["FlipView"] = 0;
                    break;
                case 1:
                    ApplicationData.Current.RoamingSettings.Values["FlipView"] = 1;
                    break;
                case 2:
                    ApplicationData.Current.RoamingSettings.Values["FlipView"] = 2;
                    break;
                case 3:
                    ApplicationData.Current.RoamingSettings.Values["FlipView"] = 3;
                    break;
            }
            this.Frame.Navigate(typeof(MainPage));
        }



回答3:


It is too easy. Just use below code on page leave:

this.NavigationCacheMode = NavigationCacheMode.Disabled;

And use below code on page constructor:

this.NavigationCacheMode = NavigationCacheMode.Enable;


来源:https://stackoverflow.com/questions/28134285/how-to-remove-a-specific-page-from-navigation-cache-in-windows-phone-8-1-rt

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