When navigating between pages in a Windows Store application you will often wish to pass some data to the destination page. For example a “Browse Photos” page in a photo browsing application would need to pass the selected photo to a “View Photo” page.
The NavigateTo(…) method includes an overload that supports passing an argument to a page,
Note that whilst the ‘arguments’ parameter can be of any type, there are a number of restrictions that should be observed in practice,
To enable a page to accept arguments the destination view-model should implement the IActivatable interface.
Upon navigation the Okra App Framework will create the page and view-model as usual, followed by a call the Activate(…) method. This method will only be called once and prior to display of the view. This method is passed a PageInfo object that contains the information required to describe the destination page. By calling the PageInfo.GetArguments<T>() method you can obtain the arguments passed from the source page (the type argument ‘T’ should match the type used in the NavigateTo(…) method).
Note that if session state storage is not being implemented then the SaveState(…) method can be empty.
For example in our hypothetical photo browsing application the “BrowsePhotos” view-model would be implemented as shown below. Note that we pass the photo ID rather than the photo object itself.
The corresponding “ViewPhoto” view-model is written as,