Windows 8 RT App - 在页面之间传递信息

时间:2014-08-26 16:23:06

标签: sqlite windows-runtime winrt-xaml

我使用SQLite存储数据,我有一个类:

class Customers
{
    [PrimaryKey, AutoIncrement]
    public int Id { get; set; }

    [MaxLength(30)]
    public string customerNumber { get; set; }

    [MaxLength(100)]
    public string customerName { get; set; }


}

我如何发送数据:

private void customer_Click(object sender, ItemClickEventArgs e)
    {
        Customers customer = e.ClickedItem as Customers;

        if(customer != null)
        {
            Customers c = new Customers();
            c.customerName = customer.customerName;
            c.customerNumber = customer.customerNumber;
            c.Id = customer.Id;
            this.Frame.Navigate(typeof(customerDetail), c);
        }
    }

我需要在详细信息页面的文本框中显示数据。

2 个答案:

答案 0 :(得分:0)

您需要访问DetailsPage上的数据吗?你在这里:

    public sealed partial class DetailPage : Page
    {
      public DetailPage()
      {
        this.InitializeComponent();
      }

      protected override void OnNavigatedTo(NavigationEventArgs e)
      {
        base.OnNavigatedTo(e);

        Customers customer = (Customers)e.Parameter;

        //Now you can get it from customer object
      }
    }

答案 1 :(得分:0)

这就是我解决它的方法:

来自Page:

private void customer_Click(object sender, ItemClickEventArgs e)
    {
        Customers customer = e.ClickedItem as Customers;

        if(customer != null)
        {
            Customers c = new Customers();
            c.customerName = customer.customerName;
            c.customerNumber = customer.customerNumber;
            c.Id = customer.Id;
            Frame.Navigate(typeof(customerDetail), c.Id.ToString());
        }
    }

到Page:

protected override void OnNavigatedTo(NavigationEventArgs e)
    {

        string custId = e.Parameter as string;
        int custIDLookup = Convert.ToInt32(custId);
        lookUp(custIDLookup);
        navigationHelper.OnNavigatedTo(e);


    }