I want to learn how to manage the state of a page between navigation. for example a navigate onto page1 and then i navigate to page2, but when i navigate back to page1, the UI elements must already be there with the same data as before and they must not be re-initialized or data must not be binded again by the compiler. Also what I can do to manage state of whole application such that, I terminate the app and then when i launch it next time, the same state is already there as last time. can i apply it on whole application? or what if I only want to apply it on a few pages? any help would be appreciated thanks.
相关问题
- Inheritance impossible in Windows Runtime Componen
- How to update parent state and child components pr
- How can I overwrite a file in UWP?
- Dynamic styling based on a state
- Accessing AppState in AppDelegate with SwiftUI'
相关文章
- Show flyout using BottomAppBar
- Why is this factory returning a $$state object ins
- Could not find a suitable SDK to target
- GridView is scrolling back to top after row select
- Atomic state storage in Python?
- Opening modal using NGX and state management
- How can i create Flashlight app in uwp C#
- Xamarin Form - How To checked the checkbox on anot
For this question, you may use UIElement.CacheMode property and Frame.CacheSize property.
CacheSize
property sets the number of pages in the navigation history that can be cached for the frame, andCacheMode
property sets a value that indicates that rendered content should be cached as a composited bitmap when possible.As we know, an UWP app default using a
rootFrame
for displaying several pages, we just useNavigation
method to change the content in the frame. You can see this in theOnLaunched(LaunchActivatedEventArgs e)
method of a blank UWP app. But how to implement cache function? For example, your app has two page and one root frame. You can defineCacheSize
property in yourOnLaunched(LaunchActivatedEventArgs e)
method for example:Then in your two pages's constructed functions enable
CacheMode
property for example:For this question, you will need to save the page state in the
OnSuspending(object sender, SuspendingEventArgs e)
method using Frame.GetNavigationState method, and you can save this state into the app's local settings. For example:And how to retrieve this informaton? You can override your
OnLaunched(LaunchActivatedEventArgs e)
method, and at first you will need to judge how is your app be closed last time, by user, or by system using ApplicationExecutionState enumeration, for example like this:But be aware that when an app is closed, next time you launch this app, the UI elements will be re-initialized, this function can only navigate to the page when the last time you close your app, but the data in that page will be lost. But you can also save the data to the local settings and when you navigate to the page, set the value to those UI elements.