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;