0

I'm looking for the best practice on how to pass data from page to page.

In Page A I have a button that fires off Page B. On Page B I have 6 textboxes that allow the user to enter information. When the user is done, the click on a button stores the information to a list, and brings them back to Page A.

I want to pass that data (list) back to Page A.

I'm looking for the Best practice. What is generally accepted as the best way?

Thanks

  • Have you tried `static` variables or [PhoneApplicationService.Current.State](http://msdn.microsoft.com/en-us/library/windowsphone/develop/ff967547(v=vs.105).aspx)? There is already [similar question](http://stackoverflow.com/questions/4953491/passing-data-from-page-to-page?rq=1). – Romasz Mar 28 '14 at 10:41
  • Yes, I've seen, it. But does this also work with lists, and how? Could you give an example, because I don't get it... – TheMauritsD Mar 28 '14 at 15:04
  • I've added sample code - but have you tried something? – Romasz Mar 28 '14 at 15:35

2 Answers2

0

This question is an exact duplicate of this question.

This is the best answer to me.

PhoneApplicationService.Current.State["yourparam"] = param
NavigationService.Navigate(new Uri("/view/Page.xaml", UriKind.Relative));

then in other page simply

var k = PhoneApplicationService.Current.State["yourparam"];
Community
  • 1
  • 1
Mani
  • 1,364
  • 14
  • 33
0

You can use PhoneApplicationService.Current.State which will surely work with List:

//create Dictionary
List<int> numbers = new List<int> { 1, 3, 4, 5 };

// add to Dictionary
PhoneApplicationService.Current.State.Add("test", numbers);

// then change in disctionary if already added
PhoneApplicationService.Current.State["test"] = numbers;

// retrive from Dictionary
List<int> newList = PhoneApplicationService.Current.State["test"] as List<int>;

This method has one big advantage - your data will be preserved in Tombstone state.

You can think about using static variable (which is accessible through your namespace. You can also follow this article and pass your List by NavigationService - I've written something about that in this answer.

Community
  • 1
  • 1
Romasz
  • 29,662
  • 13
  • 79
  • 154