当前位置: 动力学知识库 > 问答 > 编程问答 >

xaml - Universal App - restore view state in splitview navigation

问题描述:

What's the best approach to restore a view "state" when user choose to go back.

For example, a first view "UserList" witch contains a listview of many contacts, and a second view with contact details . How to retrieve the state (including scrollview position etc...) when user back to "UserList" view ?

网友答案:

Finally, the simple way is to use

NavigationCacheMode = NavigationCacheMode.Enabled

in the code behind page.

网友答案:

You should use in the Content of the SplitView a Frame, with that when you go back it will restore the previous content with the same information, I strongly recommend you to take a look to the https://github.com/Microsoft/Windows-universal-samples And look for the example about XAMLNavigation it includes all the matter about navigation.

Apart of course I recommend you to use MVVM and bind all the properties you want to store like the Contacts, etc.

网友答案:

What Juan Pablo is telling you about using MVVM is a good point! Best way is to 'store / cache' the ViewModel when navigating away and retrieving it again when you navigate back.

If you don't want to set the NavigationCacheMode for your view ( because setting this will acquire more memory ), you can use the ListViewPersistenceHelper to retain ListView scroll positions!

An example of that is up on Shawn Skendrot his blog here http://visuallylocated.com/post/2015/07/23/Persist-ListView-scroll-position-without-setting-NavigationCacheMode.aspx

分享给朋友:
您可能感兴趣的文章:
随机阅读: