How to remove a specific page from Navigation cach

2019-08-09 19:59发布

问题:

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;