WinRT - 导航到导航堆栈中的特定页面

WinRT - Navigate to specific page in the Navigation Stack

我在一个 windows 项目中有这些页面

page1.xaml

page2.xaml

page3.xaml

page4.xaml

我在第 1 页上做了一些操作后,我称之为;

Frame.Navigate(typeof(page2), document);

在第 2 页上,我对文档做了一些处理,然后导航到 page3.xaml

Frame.Navigate(typeof(page3), document);

然后我在第 3 页再做一些事情然后转到 page4.xaml。

在 page4.xaml 中我有一个按钮,当我按下它时我想回到第 2 页,xaml 不是新按钮,而是我原来的按钮。

这可能吗?

要导航到 page2 的同一实例,您需要将页面的 NavigationCacheMode 属性 设置为 EnabledRequired :

NavigationCacheMode="Enabled" 

现在这两者的区别在于他们是否考虑了 CacheSize, 来自 msdn :

The difference in behavior is that Enabled might not be cached if the frame's cache size limit (CacheSize) is exceeded, whereas Required always generates an entry no matter the size limit.