سؤال

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.

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

How can I cache a page like the way it was done previously so user will be on the same position on a list where he left?

(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;
    }

نصائح أخرى

In App.cs you can set RootFrame.CacheSize which hints the OS how many pages it should try to keep in cache. Also you probably shouldn't reset the datacontext in NavigationHelper_LoadState - this method is called each time you navigate to the page, even if you navigate back.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top