当前位置:首页 > 操作系统 > Windows

c# – 如何在Windows Phone 8.1中缓存页面

以前在Windows Phone 8.0应用程序中,我们可以通过这种方式更深入地浏览同一页面:

<code>NavigationService.Navigate(new Uri("/SamePage.xaml", UriKind.Relative));
</code>

页面自动缓存,因此在导航回来后,用户离开时列表上的位置相同.

但在Windows Phone Store应用中,我们通过这种方式更深入地浏览同一页面:

<code>Frame.Navigate(typeof(SamePage), id);
</code>

但是在导航回来之后它会再次加载数据,所以如果用户位于长列表的中间位置,那么现在他位于顶部:

<code>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;
}
</code>

如何像以前那样缓存页面,这样用户将在他离开的列表中的相同位置?

(我也包括Windows应用程序,因为他们从较长时间就熟悉它).

解决方法:

在您的页面构造函数中,您必须指定

<code>    public MainPage()
    {
       this.InitializeComponent();
       this.NavigationCacheMode = NavigationCacheMode.Required;
    }
</code>

【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!

相关教程推荐

其他课程推荐