从页将数据传递到页面的Windows Phone 8.1 [英] Passing Data from Page to Page for Windows Phone 8.1

查看:133
本文介绍了从页将数据传递到页面的Windows Phone 8.1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从页面将数据传递到页面确切同样的问题 ,但仅限于Windows Phone的8.1(相对于Windows Phone 7的)。这里有一个问题:

I have the exact same question as Passing data from page to page, but only for Windows Phone 8.1 (opposed to Windows Phone 7). Here is the question:

我在寻找如何从页面数据传递给页面的最佳做法。

I'm looking for the best practice on how to pass data from page to page.

在第一个我有一个按钮,触发了页面B.
第B我有6文本框,允许用户输入信息。当用户完成,这使他们回到网页A上的按钮点击。

In Page A I have a button that fires off Page B. On Page B I have 6 textboxes that allow the user to enter information. When the user is done, the click on a button that brings them back to Page A.

我想通过这些数据回页A

I want to pass that data back to Page A.

我见过的建议:

构建XML文档并保存到独立存储
使用App类来存储属性的信息
通过它像一个查询字符串
我正在寻找的最佳实践。是否有一个Microsoft建议或一个被普遍接受的最佳途径?

build XML documents and save to Isolated Storage use the App class to store information in properties pass it like a query string I'm looking for the Best practice. Is there one that Microsoft recommends or one that is generally accepted as the best way?

感谢

推荐答案

在WP8.1运行 - 对的Silverlight 的,的在WP8.0 使用的方法仍然应该努力 - 你有几个choces的:

In WP8.1 Runtime - for Silverlight, the methods used in WP8.0 still should work - you have couple of choces:


  • 第一,可能是最简单的方法是使用导航带参数 - 你不必将它转化成的字符串的,如果它是一个序列化类型:

  • the first and probably the easiest way is to use Navigate with parameter - you don't have to convert it to string if it's a serializable type:

// let's assume that you have a simple class:
public class PassedData
{
   public string Name { get; set; }
   public int Value { get; set; }
}

// then you navigate like this:
Frame.Navigate(typeof(Page1), new PassedData { Name = "my name", Value = 10 });

// and in target Page you retrive the information:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
    PassedData data = e.Parameter as PassedData;
}


  • 您可以使用一些的静态对象的传递数据一起在App

  • you can use some static objects to pass your data along the App

    请注意,您还必须处理应用程序的暂停/恢复 - 所以这将是适合保存数据的应用程序被挂起时,当它重新加载。你应该记住的的OnNavigatedTo 的,当应用程序在恢复不会被调用。

    Note that you will also have to handle app suspending/resuming - so it will be suitable to save your data when the app is being suspended and load when it's resumed. You should remember that OnNavigatedTo is not being called when the app is resuming.

    以上是关于正常航行(前进)。如果您要填写previous页一些数据,那么你有两个选择:

    The above was about normal navigation (forward). If you want to fill some data in previous Page, then you have a couple of options:


    • 传递处理到previous页,这样你就可以从当前的页面访问公共变量/属性,

    • 使用静态变量/属性 - 可能是单身

    • 再次使用文件/设置

    注意,再前两种方法的缺点在于,应用程序可能被暂停之后崩溃。保存到文件可能会在这里好,思想需要一些更多的工作和妥善处理。

    Note that again the first two methods has a disadvantage that the app may crash after being suspended. Saving to files might be better here, thought needs some more work and proper handling.

    这篇关于从页将数据传递到页面的Windows Phone 8.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆