如何在 Windows Phone 8.1 中缓存页面 [英] How to cache a page in Windows Phone 8.1
问题描述
以前在 Windows Phone 8.0
应用程序中,我们可以通过这种方式更深入地导航到同一页面:
Previously in Windows Phone 8.0
apps, we could navigate deeper to the same page this way:
NavigationService.Navigate(new Uri("/SamePage.xaml", UriKind.Relative));
页面被自动缓存,所以导航回来后,用户离开时在列表中的同一位置.
Page was cached automatically, so after navigating back, user was on the same position on the list when he left.
但是在 Windows Phone Store Apps
中,我们通过这种方式更深入地导航到同一页面:
But in Windows Phone Store Apps
we navigate deeper to the same page this way:
Frame.Navigate(typeof(SamePage), id);
但是在导航回来后它会再次加载数据,所以如果用户在一个长列表的中间,现在他在顶部:
But after navigating back it loads data again so if user was on the middle of a long list, now he is on the top:
private async void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
{
// TODO: Create an appropriate data model for your problem domain to replace the sample data.
var group = await SampleDataSource.GetGroupAsync((string)e.NavigationParameter);
this.DefaultViewModel["Group"] = group;
}
我怎样才能像以前那样缓存页面,以便用户在他离开的列表中处于相同的位置?
(我也包含了 Windows 应用程序,因为他们很早就熟悉它了).
(I included Windows apps too cause they are familiar with it from a longer time).
推荐答案
在你的页面构造器中,你必须指定
In your page constructor you'll have to specify
public MainPage()
{
this.InitializeComponent();
this.NavigationCacheMode = NavigationCacheMode.Required;
}
这篇关于如何在 Windows Phone 8.1 中缓存页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!