I have a program with MainWindow.xaml, MainWindow.xaml.cs, and Helper.cs files. All the UI is in the .xaml file and can only be accessed from the .xaml.cs file. But now I want to change the text in a TextBox in the MainWindow.xaml file from the Helper.cs file, which is completely separate.
I've tried creating a function in MainWindow.xaml.cs to do that:
public void SetRNrInfoText(string value)
{
this.RNrInfoTextBox.Text = value;
}
or
public string RNrInfoText
{
get { return this.RNrInfoTextBox.Text; }
set { this.RNrInfoTextBox.Text = value; }
}
In Helper.cs file, I use:
public static void searchByRNR()
{
MainWindow mainWindow = new MainWindow();
mainWindow.SetRNrInfoText("new text");
}
However, when I try to call this searchByRNR function, nothing happens. In the .xaml file, "x:FieldModifier" is set to "public".
For now, the only idea I have is to make Helper return a dictionary or an array, and then in MainWindow, set all the values to certain textboxes, but I don't really like that idea.
So the question is, can I somehow change the property of a .xaml element in another .cs file, or is it not possible?"