Recovering the application status when selecting an item in Gridview

Asked

Viewed 70 times

0

Hello, I’m creating a universal application for Windows 10 in C#. On the home screen is a Gridview loading dozens of items. I would like to know how I should save the selected item without needing to do so when I return to the home screen, slide until I reach the last seen item ? Thank you.

  • Would you like the item?

  • No, whenever I select an item and navigate to the other screen, on the way back it doesn’t click where I left it, it reloads the list as if it had opened the app for the first time

  • 1

    There is no way to save the index of the selected item, like the cookie we use on web pages?

  • Well, then I have to think of something. Until now I have 41 items in gridview, until I reach 39 I have to slide my finger on the screen until I arrive, after I click and navigate to the second screen and back, I will have to slide everything again to arrive and select item 40.

1 answer

1

Hello.

Just use the navigation cache NavigationCacheMode. There are three modes:

NavigationCacheMode = NavigationCacheMode.Disabled - The page is not cached, that is, after exiting the screen and returning, the screen will be rebooted.

NavigationCacheMode = NavigationCacheMode.Enabled - The page will be cached as long as there is leftover memory, but if the application needs more memory, it will be cached.

NavigationCacheMode = NavigationCacheMode.Required - The page is kept cached at all costs, even if there is no more memory available.

Add this at page startup, right after the InitializeComponent()

After this, when navigating to the second screen and returning the home screen will remain unchanged (if you choose the option Requiredor Enabled).

Note that the cache control is done individually on each page. Page 1 cache will not affect page 2.

  • Man you saved the fatherland. Thank you so much

Browser other questions tagged

You are not signed in. Login or sign up in order to post.