Going to the details page - general view model or navigation query string?

When navigating from a list page to a details page, there are two ways to transfer data between pages between a high level: sharing a view model instance and passing an identifier in the Uri navigation query string.

What should i use? Are there any problems using one approach over another (access to the current Uri from the view model, time of navigation events, etc.)?

+6
source share
2 answers

Personally, I would recommend passing the identifier as part of the navigation URI. These URIs are restored to form a back-stack when your application turns back on after the add-in.

When your application recovers after it has been destroyed, you re-create the application view model from the application state, and then use the request URI button to β€œmarry” your newly created view with its required DataContext.

See the example here:

http://www.scottlogic.co.uk/blog/colin/2011/05/a-simple-windows-phone-7-mvvm-tombstoning-example/

+8
source

The two matches are pretty good.

the real difference lies in the gravestone .

when you return to your application, the identifier of your object will be analyzed:

  • in the query string. (Native)
  • with your specific isolated storage management.

if you choose a general view model, you will need to save the identifier when navigating.

the combination of the two is apparently the best: you navigate using queryString and use sharedViewModel, so when you go to a new page, you get an identifier from queryString and get data from sharedViewModel with that identifier!

you can control SharedViewModel to save data in Inventory to recover loaded web data when memmbonstock

+1
source

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


All Articles