I am building an interface in WPF. My MainWindow class has access to the TextBlock that I created in the window. It can write text to this TextBlock by just calling the textblock.text method.
I then created a second class, that is instantiated immediately when the program starts. This class has a method I created that cannot see that textblock. How would I be able to access that .text method that is accessible in MainWindow?
Thanks
MainWindow.xaml.cs
{
ButtonFunctions buttonFunctions = new ButtonFunctions();
public MainWindow()
{
InitializeComponent();
ProgressBar ProgBar = new ProgressBar();
}
//this works
textBlock.Text = "r";
ButtonFunctions.cs
{
public ButtonFunctions()
{
}
public void Addtext(string t)
{
//this doesn't work
textBlock.Text += t;
//this doesnt work either
MainWindow.textBlock.Text="r";
}
If I try to call the MainWindow method, I get the below error. An object reference is required for the non-static field, method or property "MainWindow.textBlock.Text" What object reference is needed in this case?