简体   繁体   English

在Windows Phone中的页面之间导航时如何保留数据

[英]how to retain data while navigating between pages in windows phone

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 data will be displayed. 在我的应用程序中,第一页(第1页)显示了项目列表,当选择一个项目时,我会将名称传递给另一个页面(第2页),并使用该名称从服务器获取数据。显示。 In the details one of them would be category (grocery,cosmetics etc), so if i click on that textbox it will be navigated to another page(page3) where you can select another category,after selecting another category its name would again be passed back to the detail page(Page2). 在详细信息中,其中一个将是类别(杂货,化妆品等),因此,如果我单击该文本框,它将被导航到另一个页面(第3页),您可以在其中选择另一个类别,在选择另一个类别之后,其名称将再次传递返回详细信息页面(Page2)。 In my second page i'll get the data with the following code, 在第二页中,我将使用以下代码获取数据,

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
}
}

but when i come back from page3 to page2, all the details i displayed(by getting the name from page1) is found missing. 但是当我从第3页回到第2页时,发现我显示的所有详细信息(通过从第1页获得名称)都丢失了。 How can i retain that data?? 我如何保留这些数据?

These are the possible ways to pass data while navigating between pages in windows phone 这些是在Windows Phone中的页面之间导航时传递数据的可能方法

  1. Store data on Windows Phone 7 by using Isolated Storage 使用隔离存储在Windows Phone 7上存储数据
  2. Pass data through parameter between pages 通过页面之间的参数传递数据
  3. Dynamic generate data grid, which contains data and related link button 动态生成数据网格,其中包含数据和相关的链接按钮
  4. Use XElement, XAttribute as data structure 使用XElement,XAttribute作为数据结构

For Reference see here 供参考,请看这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM