Save scroll status in Windows Phone 8.1 when user navigates between pages

I navigate between pages using the navigation assistant class added by VS 2013 when creating the solution. But the scroll state of most controls (for example, Pivot, Hub) is not saved, as in Windows Phone 8.x Silverlight.

What should I do to implement this behavior? Do I have to handle the scroll state myself and restore the scroll when I return to the visited page?

Thanks.

Update1:

I need to save the selected pivot / hub element etc. when I return to the page.

UPDATE2:

void navigationHelper_SaveState(obj sender,SaveStateEventArgs e) { e.PageState["SelectedSection"] = MainHub.SectionsInView; } void navigationHelper_LoadState(obj sender,LoadStateEventArgs e) { if (e.PageState != null) { var sections = e.PageState["SelectedSection"] as IList<HubSection>; if (sections != null && sections.Any()) MainHub.ScrollToSection(sections[0]); } } 
+6
source share
2 answers

On the page where you use the hub, set the navigation caching mode in the designer:

 this.NavigationCacheMode = NavigationCacheMode.Enabled; 

or in XAML:

 <Page x:Class="App.HubPage" .... xmlns:data="using:App.Data" NavigationCacheMode="Enabled" .... 
+12
source

Best use:

 this.NavigationCacheMode = NavigationCacheMode.Required; 

front:

 this.InitializeComponent(); 

And add:

 protected override void OnNavigatedFrom(NavigationEventArgs e) { if (e.NavigationMode == NavigationMode.Back) this.NavigationCacheMode = NavigationCacheMode.Disabled; } 

to remove the cache during reverse navigation from the page.

+1
source

Source: https://habr.com/ru/post/969803/


All Articles