2015-01-14 12 views
0

我需要传递列表框中的选定项目来编辑页面。我使用此代码从listBox中获取数据,但我不知道如何将类Tasks传递到下一页。Widndows手机 - 传递填充类到另一个页面

private void HoldingItem(object sender, HoldingRoutedEventArgs e) 
    { 

FrameworkElement element = (FrameworkElement)e.OriginalSource; 

    Tasks tsk = (Tasks)element.DataContext; 

//我填补了类,但我不知道热,以获得另一页

 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 

     } 

谢谢

回答

0

传递对象并不那么容易。 你应该阅读这篇文章的详细信息: 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); 
} 
0

You ne编辑到类型e.ParamaterTasks(ie。)到您传递的对象的类型。

var objectFromPage1=(e.Parameter as Tasks); 
0

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

请注意,不同的页面没有连接,您不应直接移交对象。

相关问题