0

I have a two xaml page. I am trying to passing a list array of string from one page to another during navigation. I can easily pass the string object but not able to pass the collection object. Can anyone please help me. I have write the code as below.

First xaml

List<string> array = //contains the array of strings
NavigationService.Navigate(new Uri("/ListViewController.xaml?parameter="+array, UriKind.Relative));

Second xaml i.e ListViewController.xaml

protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
string msg;
if (NavigationContext.QueryString.TryGetValue("parameter",out msg))
{
foreach (char str in msg)
Debug.WriteLine("Data "+ str);
}
}
Rajesh
  • 764
  • 8
  • 16
  • 2
    You can use string join method to separate the array. String.Join(",", array.ToArray());. Note : Query string limitation, refer : http://stackoverflow.com/questions/14718933/how-to-send-long-query-string-in-windows-phone-with-httpwebrequest In destination page, split query string parameter using separator. - var data= msg.Split(','); – Deepu Madhusoodanan Jul 15 '13 at 04:55
  • This can be helpful: http://stackoverflow.com/questions/4953491/passing-data-from-page-to-page – anderZubi Jul 15 '13 at 07:33

2 Answers2

0

You can try this

Pass non-string parameters between pages in Windows Phone 8 app

Alen Lee
  • 2,479
  • 2
  • 21
  • 30
0

This work for ObservableCollection so I hope will work for List. You can pass collection by parametr of Navigate method:

    ObservableCollection<string> gifts = new ObservableCollection<string>();

    private void GoToMoreButton_Click(object sender, RoutedEventArgs e)
    {
         this.Frame.Navigate(typeof(MoreOptionPage), gifts);
    }

And get it in destination page:

protected override void OnNavigatedTo(NavigationEventArgs e)
{
     gifts2 = e.Parameter as ObservableCollection<string>;
}
scorpion
  • 671
  • 1
  • 9
  • 16