I'm using the NavigationContext.QueryString for my Windows Phone 8 app. For example, I set an URI identifier like ItemId in the navigation string and in the OnNavigatedTo, I parse the Id and read the Item via linq.
protected override void OnNavigatedTo(NavigationEventArgs e)
{
try
{
int itemId = int.Parse(NavigationContext.QueryString["itemId"]);
_item = App.MainViewModel.GetItem(itemId);
DataContext = _item;
}
catch (KeyNotFoundException ex)
{
Debug.WriteLine(ex.Message);
throw;
}
}
I've found an interesting alternative and want to hear your opinion:
// in the calling page
PhoneApplicationService.Current.State["Item"] = App.MainViewModel.GetItem(123);
// in the destination page
Item item = PhoneApplicationService.Current.State["Item"] as Item;
Is this really a recommended way?