如何在 UWP 中通过多个页面传递对象 [英] How to pass objects through multiple pages in UWP

查看:25
本文介绍了如何在 UWP 中通过多个页面传递对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的任务是创建一个需要通过多个页面传递学生对象的多页面 UWP 应用程序.该应用从主页开始,那里有两个按钮,一个用于添加新学生,另一个用于查看学生的详细信息.

I am tasked with creating a multi-page UWP app that needs to pass a student object through multiple pages. The app starts on the main page where there are two buttons, one to add a new student and then and the other to then view the students details.

我目前正在努力弄清楚如何将学生对象从新学生页面"传递到学生详细信息"页面.我不允许将学生信息存储在文件或数据库中.

I am currently struggling trying to figure out how to pass the student object from the "new student page" to the "student details" page. I'm not allowed to store the students information in a file or database.

添加新学生后,信息应存储在 Student 对象中,是否可以将此对象设为公开,以便无需通过页面即可使用?是否也可以将学生详情页上的文本块绑定到来自输入页的学生对象?

When a new student has been added the information should be stored within the Student object, is it possible to make this object public so that it can be used without passing it through pages? Is it also possible to bind the text blocks on the student details page to the student object that is from the input page?

推荐答案

您可以使用您的 Student 类对象,然后在 Navigate 将其传递到另一个页面作为范围.

You can use your Student class object and then pass it to another page when Navigate to it as parameter.

New Student页面:

void ButtonShowDetails_Click(sender , ....)
{
  var student = new Student();
  student.Name="Joe";// or txtStudentName.Text
  /// etc
  /// etc
  Frame.Navigate(typeof(pgStudentDetails), student);
}

pgStudentDetails 页面中:

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    base.OnNavigatedTo(e);
    var param = (Student)e.Parameter; // get parameter
    txtName.Text= param.Name;//show data to user
}

这篇关于如何在 UWP 中通过多个页面传递对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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