---
title: "Editing XAML textbox not from MainPage class"  
description: "Editing XAML textbox not from MainPage class"  
author: "Mark Devid"  
published: 2014-03-29  
updated: 2014-03-29  
canonical: https://www.mindstick.com/forum/1998/editing-xaml-textbox-not-from-mainpage-class  
category: "wpf"  
tags: ["wpf"]  
reading_time: 1 minute  

---

# Editing XAML textbox not from MainPage class

I have the MainPage class which I can edit the contents of the XAML [textbox](https://www.mindstick.com/forum/12714/dynamic-textbox-in-gridview) from using this code

box1.Text = "";

however [trying](https://answers.mindstick.com/qa/93698/6-mistakes-couples-are-trying-to-save-money) to edit the textbox from another class the following code will do not work

MainPage.box1.Text = "";

The error is "An [object reference](https://www.mindstick.com/forum/376/system-nullreferenceexception-object-reference-not-set-to-an-instance-of-an-object) is [required](https://www.mindstick.com/forum/160269/what-is-required-data-annotation-how-does-it-affect-model-validation) for the non-[static](https://www.mindstick.com/articles/12098/the-static-keyword-the-static-methods) field, [method](https://www.mindstick.com/forum/166/webservice-method) or [property](https://www.mindstick.com/blog/205/property-notification-in-c-sharp) 'class.MainPage.box1' I have tried everything like making static [functions](https://www.mindstick.com/forum/160140/explain-the-role-of-functions-as-a-service-faas-in-serverless-computing) and creating new MainPage [objects](https://www.mindstick.com/forum/145447/what-are-objects) in the other class but nothing has worked.

## Replies

### Reply by Pravesh Singh

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 = "";


---

Original Source: https://www.mindstick.com/forum/1998/editing-xaml-textbox-not-from-mainpage-class

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
