c# - Xamarin - 如何将对象传递给事件处理程序
问题描述
免责声明- 我需要一些指导,因为我对 C# 和 Xamarin非常陌生。非常感谢示例。
基本上,我在 Page1 中有一个名为“newuserdata”的对象,我将其传递给 Page2。
第 1 页 - RegistrationUserPage.xaml.cs
...
else
{
Userdata newuserdata = new Userdata();
newuserdata.firstname = firstname;
newuserdata.lastname = lastname;
newuserdata.birthday = birthday;
newuserdata.phone = phone;
newuserdata.password = password;
var RegistrationUserBillingPage = new RegistrationUserBillingPage(newuserdata);
await Navigation.PushAsync(RegistrationUserBillingPage);
第 2 页 - RegistrationUserBillingPage.xaml.cs
...
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class RegistrationUserBillingPage : ContentPage
{
public Userdata newuserdata;
public RegistrationUserBillingPage(Userdata newuserdata)
{
InitializeComponent();
this.newuserdata = newuserdata;
// this works fine and I get the data
first.Text = newuserdata.firstname;
}
async void SubmitButton_Clicked(object sender, EventArgs e)
{
//How do I get the object to this event so that I could get or set the values?
// I would like to get the value
/*
second.Text = newuserdata.lastname;
*/
// .. and I would like to set the value
/*
newuserdata.city = CityEntry.Text;
*/
}
}
}
所以问题是 - 我如何在我的“SubmbitButton_Clicked”方法中访问对象?
解决方案
你试过 this.newuserdata.lastname 吗?- 一个朋友
我没有正确触发事件。谢谢@朋友!
推荐阅读
- r - 创建每月吸收率图
- excel - 如何使用单个公式计算条件中位数数组的平均值?
- javascript - 根据数据库变量生成“n”个 html 输入
- c# - 从 Datagridviewcells 更新 Oracle 表
- r - 提取多边形质心的坐标并按多边形编号对其进行标记
- javascript - 如何在 a 中左右浮动元素标签?
- javascript - ForEach 中的 setTimeout 不会等待给定的特定毫秒
- string - 带有三元运算符的 Java SE 11 字符串最终变量在 Switch Case 表达式中不计为常量变量
- go - 如何启动多个机械工人?
- c++ - 在创建和不创建模板的情况下递增迭代器