将对象从视图A传递到视图B.

时间:2018-04-22 21:28:11

标签: c# xamarin

我在视图A中构造了一个对象。我打算将此对象传递给视图B,然后在标签中打印对象的参数。不幸的是,我不允许在视图B中访问对象的参数。我收到错误"对象不包含' hrs'&#34的定义;

视图中的代码A:

async void Calculate_btn(object sender, EventArgs e)
{

    Calculation calc = new Calculation()
    {
        hrs = "qwe",
        cse = "rty",
        aqe = "uio"

    };



    var page = new Results(calc);
    await Navigation.PushModalAsync(page);
}

视图中的代码B:

public Results(object number)
{

    InitializeComponent();
    string hours = number.hrs;
    label.text = hours;
}

1 个答案:

答案 0 :(得分:-1)

你应该改变

public Results(object number)

public Results(Calculation number)