【问题标题】:how to retain data while navigating between pages in windows phone如何在 Windows Phone 中的页面之间导航时保​​留数据
【发布时间】:2013-10-24 13:39:18
【问题描述】:

In my app, first page(page1) shows the list of items, when an item is selected, i will pass the name to another page(page2) and with that name will get the data from the server.And all the将显示数据。 在详细信息中,其中一个是类别(杂货、化妆品等),所以如果我单击该文本框,它将被导航到另一个页面(page3),您可以在其中选择另一个类别,在选择另一个类别后,它的名称将再次被传递返回详情页(Page2)。 在我的第二页中,我将使用以下代码获取数据,

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
base.OnNavigatedTo(e);
if (e.Uri.OriginalString.Contains("name"))
{
    var ItemName = NavigationContext.QueryString["id"];          
    //this is a parameter from page1 
    // do something
}
else   if (e.Uri.OriginalString.Contains("category"))
{
    var CategoryName= NavigationContext.QueryString["category"];          
    //this is a parameter from page3 
    // do something
}
}

但是当我从第 3 页回到第 2 页时,发现我显示的所有详细信息(通过从第 1 页获取名称)都丢失了。 我怎样才能保留这些数据??

【问题讨论】:

标签: c# windows-phone-7


【解决方案1】:

这些是在 windows phone 中的页面之间导航时传递数据的可能方式

  1. 使用独立存储在 Windows Phone 7 上存储数据
  2. 在页面之间通过参数传递数据
  3. 动态生成数据网格,其中包含数据和相关链接按钮
  4. 使用 XElement、XAttribute 作为数据结构

参考见here

【讨论】:

  • 请注意,如果您不将数据作为 QueryString 的一部分传递,则在从墓碑化返回后可能会丢失它。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-05-14
  • 2016-10-20
  • 1970-01-01
相关资源
最近更新 更多