OnNavigatedFrom之后,页面不会自行销毁/卸载 [英] Page doesn't destroy/unload itself after OnNavigatedFrom
问题描述
我正在使用框架显示我的当前页面.用户可以在两个页面之间切换.
I am using a frame to show my current page. The user can switch between two pages.
我通过以下网址导航到页面:
I navigate to the pages via:
frame.Navigate(typeof(FirstPage));
和
frame.Navigate(typeof(SecondPage));
我认为每次切换页面时,旧页面都会被存储/卸载所有内容.
I thought that every time I switch between the pages the old page will be destoyed/unload all it's content.
但是从内存使用情况来看,它看起来并不像这样:
But looking on the memory usage, it doesn't look like it:
(每次导航到SecondPage
时,我都会运行垃圾收集器,以便您可以看到何时进行导航)
(every time I navigate to the SecondPage
I run the garbage collector so you can see when a navigation occured)
我必须更改frame.Navigation()
方法还是必须在OnNavigationFrom()
方法中添加一些内容?
Do I have to change the frame.Navigation()
method or do I have to add something to the OnNavigationFrom()
method?
推荐答案
如果您不希望应用程序导航后占用更多内存,只需设置属性移至NavigationCacheMode.Required
.
If you don't want the app to cosume much memory after navigation, just set the NavigationCacheMode
property on your pages to NavigationCacheMode.Required
.
您的应用不会在每次导航到页面时都为其创建新实例.
Your app will not be creating new instances of the pages everytime you navigate to them.
这篇关于OnNavigatedFrom之后,页面不会自行销毁/卸载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!