I was recently having some issues with a bigger project, but in an effort to solve the problem, I made a new solution with just two incredibly basic files. It is a WPF C# project with the main window containing a button, and a usercontrol containing a textblock. I already have them linked in Blend so that when I click the button, the usercontrol comes up. However, when I added code to change the text in the usercontrol's textblock from the mainwindow, it gives me this error: An object reference is required for the non-static field, method, or property TestingUserControls.TestControl.sampleText.get'
I like usercontrols and we are using them all throughout our project, but for some reason I just cannot get them to work well.
The code for my usercontrol is this:
public TestControl()
{
this.InitializeComponent();
}
public string sampleText
{
get { return blkTest.Text; }
set { blkTest.Text = value; }
}
The code for the main window is this:
public MainWindow()
{
InitializeComponent();
}
private void button1_Click(object sender, System.Windows.RoutedEventArgs e)
{
TestControl.sampleText.set("Sup");
}