I use NavigationContext.QueryString for my Windows Phone 8 application. For example, I set the URI, for example ItemId, in the navigation bar and OnNavigatedTo, I will parse the identifier and read the item through 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 found an interesting alternative and I 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 the recommended way?
source share