如何在Windows Phone 8.1中缓存页面 [英] How to cache a page in Windows Phone 8.1

查看:57
本文介绍了如何在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆