Windows phone - 将 fill class 传递到另一个页面

Widndows phone - pass fill class to another page

我需要将列表框中的选定项目传递给编辑页面。我正在使用此代码从 listBox 获取数据,但我不知道如何将 class 任务传递到下一页。

  private  void HoldingItem(object sender, HoldingRoutedEventArgs e)
    {

FrameworkElement element = (FrameworkElement)e.OriginalSource;

  Tasks tsk = (Tasks)element.DataContext;  

// 我填写了 class 但我不知道如何在另一页上获取数据

        Frame.Navigate(typeof(Edit), tsk); 

}

页面编辑 - 获取参数

     protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            this.navigationHelper.OnNavigatedTo(e);

  testlbl.Text = e.Parameter.ToString();  //it doesnt work. I can't manage the class

        }

谢谢

您需要将 e.Paramater 类型转换为 Tasks(即。)您要传递的对象类型。

 var objectFromPage1=(e.Parameter as Tasks);

您应该将对象存储在模型中的某处,并将一些标识符作为参数传递。

注意不同页面之间没有关联,不要直接交对象

传递对象没那么容易。 您应该阅读这篇文章了解详情: http://www.geekchamp.com/tips/how-to-pass-data-between-pages-in-windows-phone-alternatives

对于复杂的对象,您应该遵循以下模式: http://www.geekchamp.com/articles/wp7-master---detail-navigation-with-repository-pattern

基本思路很简单。您可以将对象存储在某种存储(存储库)中,将对象的 Id 传递给下一页,然后通过 Id 从存储中检索对象。

当您准备好导航时

NavigationService.Navigate(new Uri(string.Format("/Page.xaml?parameter={0}",item.Id ), UriKind.Relative));

然后在您的页面上读取查询中的 ID:

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
    base.OnNavigatedTo(e);
    string parameterValue = NavigationContext.QueryString["parameter"];   
    int id = Int32.Parse(parameterValue);
    var yourItem = _storage.GetById(id);
}