editing XAML textbox not from MainPage class

前端 未结 2 1868
情书的邮戳
情书的邮戳 2021-01-27 14:00

I have the MainPage class which I can edit the contents of the XAML textbox from using this code

box1.Text = \"\";

however trying to edit the t

2条回答
  •  感情败类
    2021-01-27 14:45

    XAML Textbox is in MainPage.xaml/.cs

    Your value setter for the Textbox is in some class X.

    The reason for your error on below statement is, the box1 is not static and you need an instance of the MainPage.

    MainPage.box1.Text = "";
    

    But not just any instance. You need the current instance. So the method in the class X, needs to receive a "THIS" instance of MainPage.xaml.cs class and then change the box1 value.

    The function call:

    X xobj=new X();
    xobj.ChangeboxValue(this);
    

    The function:

    void ChangeboxValue(MainPage obj)
    {
    obj.box1.Text=""
    }
    

提交回复
热议问题