简体   繁体   中英

UWP - How to save frame backstack and current page?

Hi I have this hierarchy

App (RootFrame)

  • Login Page
  • Main Shell (InnerFrame)
    • List Page with entities 1
    • List Page with entities 2
  • Detail Page for entity 1 (InnerFrame2)
    • subpage 1-1
    • subpage 1-2
  • Detail Page for entity 2 (InnerFrame3)
    • subpage 2-1
    • subpage 2-1

And I want to handle Back button correctly. Navigating between pages in inner frames is ok, but when I go for example from "List Page with entities 2" to "Detail page for entity 2" and then back, MainShell i recreated and forgets the InnerFrames BackStack and opened Page(should be "List Page with entities 2")

Is there any elegant way to handle this? for example save InnerFrames history and current page when navigatedFrom at MainShell happens?

You can try Prism Framework , here is a lifecycle managing example .

In a nutshell Prism provides SessionStateService to manage view restoring when OnAppSuspended and OnAppResumed events invoked.

Also Prism NavigationService passes NavigatedToEventArgs e, NavigatedFromEventArgs e, Dictionary<string, object> viewModelState parameters and your page behaviour can be overrided in OnNavigatedTo and OnNavigatedFrom using this parameters.

I found what I needed. There are SetNavigationState(string) and GetNavigationState() methods on Frame object. Thanks anyway

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM