Sorry about the title but I don't really know how to word the problem. Basically, I have a log in screen which comes up when you start the program. After the user logs in successfully, the current window is switched with
MainWindow obj = new MainWindow(userNameTextBox.Text);
App.Current.MainWindow = obj;
obj.Show(); //after login Redirect to second window
this.Close();//after login hide the Login window
I then try to fill a datagrid on the next window but get this error.
Object reference not set to an instance of an object.
I have tried just setting the text in a label and get the same error. When I have tried setting the text in a label in the login.xml.cs code (so after the this.close line) it works using this line
obj.label.Content = "test";
Why can I not access the wpf controls in the current window?