Search code examples
windows-phone-7mvvmnavigationtombstoning

Navigating to a details page - shared view model or navigation query string?


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

Which should I be using? Are there any issues with using one approach over the other (access to current Uri from the view model, timing of navigation events, etc)?


Solution

  • Personally I would recommend passing an identifier as part of the navigation URI querystring. These URIs are restored to form the back-stack when your application re-enabled after tombstoning.

    When your application is restored after being tombstoned, you re-create your applications view model from the application state, then use the URI querystring to 'marry' your newly created view with its required DataContext.

    See the worked example here:

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