Xamarin-如何将对象传递给事件处理程序

时间:2019-07-25 08:12:35

标签: c# xamarin

免责声明-我需要一些指导,因为我非常是C#和Xamarin的新手。例子是极大的赞赏。

基本上,我要传递给Page2的Page1中有一个名为“ newuserdata”的对象。

第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”方法访问对象?

0 个答案:

没有答案
相关问题