In order to navigate my application you are presented with the Mainwindow on load up. There is a button that you can click that opens the TeacherTools window. From here you are able to add new students to the list. On this window I have a back button that will return you to the MainWindow and I can confirm that the information is still usable here. I'm having an issue whereby I open a 3rd window which is a Exam window in which students are presented with questions afterwards and their score should be added to the currently loaded Student visa his name.
private List<Student> studentList = new List<Student>();
public partial class MainWindow : Window
{
TeacherTools teachTools = new TeacherTools();
Learning myLearning = new Learning();
private void teachAdmin_Click(object sender, RoutedEventArgs e)
{
this.Hide();
teachTools.ShowDialog();
this.Show();
}
private void Selection_Click(object sender, RoutedEventArgs e)
{
this.Hide();
myTest.studentName.Text = studentsList.SelectedValue.ToString();
myTest.ShowDialog();
this.Show();
}
}
//Exam Window
public partial class Test : Window
{
//I'm sure its not this
Student loadedStudent = new Student();
TeacherTools teachTools = new TeacherTools();
public void(private void finishTest()
{
loadedStudent = teachTools.Kids.Find(delegate(Student s) { return s.Name == studentName.Text; }); //This line
loadedStudent.Attempted = true;
loadedStudent.Score = score;
}
}
As such i'm getting a "Object reference not set to an instance of an object. - NullReferenceException". I'm not sure why this is happening because I can make modifications to a Student object from the MainWindow.
Edit: TeacherTools Class
public partial class TeacherTools : Window
{
private List<Student> studentList = new List<Student>();
public TeacherTools()
{
InitializeComponent();
}
public List<Student> Kids
{
get { return studentList; }
//set { studentList = value; }
}
private void newStudentClick(object sender, RoutedEventArgs e)
{
Student student = new Student();
student.Name = nameBox.Text;
studentList.Add(student);
studentData.ItemsSource = studentList;
studentData.Items.Refresh();
//nameBox
}
}