QueryString vs. Navigation PhoneApplicationService.Current.State

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?

+4
source share
1 answer

From MSDN :

The PhoneApplicationService class provides access to various aspects of application lifetime. This includes managing the applicationโ€™s inactivity and managing the status of applications when it becomes active or inactive. You can use it this way, but the data must be serializable.

This link has other ways of exchanging data, but I don't think this is the recommended way. This is more for tomb purposes.

0
source

All Articles