将Collection对象从一个页面传递到另一个页面

时间:2013-07-15 04:29:58

标签: windows-phone-8

我有两个xaml页面。我想在导航过程中将一个字符串数组从一个页面传递到另一个页面。我可以轻松传递字符串对象但无法传递集合对象。谁能帮帮我吗。我已经编写了如下代码。

第一个xaml

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

第二个xaml,即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);
}
}

2 个答案:

答案 0 :(得分:0)

答案 1 :(得分:0)

ObservableCollection这项工作,所以我希望能为List工作。 您可以通过Navigate方法的参数传递集合:

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

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

在目的地页面中获取它:

protected override void OnNavigatedTo(NavigationEventArgs e)
{
     gifts2 = e.Parameter as ObservableCollection<string>;
}
相关问题