Home > DeveloperSection > Forums > Editing XAML textbox not from MainPage class
Mark Devid
Mark Devid

Total Post:101

Points:707
Posted on    March-29-2014 4:16 AM

 WPF WPF 
Ratings:


 1 Reply(s)
 1063  View(s)
Rate this:

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 textbox from another class the following code will do not work

MainPage.box1.Text = "";

The error is "An object reference is required for the non-static field, method or property 'class.MainPage.box1' I have tried everything like making static functions and creating new MainPage objects in the other class but nothing has worked.



Pravesh Singh

Total Post:411

Points:2881
Posted on    March-29-2014 7:03 AM

Hi Mark,

You are trying to access a static field of the MainPage class without an object instance.

You'll need an instance of the MainPage class to access it like this:

MainPage myPage = new MainPage();

myPage.box1.Text = "";


Don't want to miss updates? Please click the below button!

Follow MindStick