내 응용 프로그램을 탐색하려면로드시 Mainwindow가 표시됩니다. TeacherTools 창을 열 수있는 버튼이 있습니다. 여기에서 새 학생을 목록에 추가 할 수 있습니다. 이 창에는 MainWindow로 돌아갈 수있는 뒤로 버튼이 있으며 여기에서 정보를 사용할 수 있음을 확인할 수 있습니다. 나는 학생들이 나중에 질문을 받고 학생들의 점수가 현재로드 된 학생 비자의 이름에 추가되어야하는 시험 창인 제 3의 창을 엽니 다.C# Windows 간의 데이터 손실
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;
}
}
이와 같이 "개체 참조가 개체 인스턴스로 설정되지 않았습니다."- NullReferenceException. MainWindow에서 Student 객체를 수정할 수 있기 때문에 왜 이런 일이 발생하는지 잘 모르겠습니다.
편집 : TeacherTools 클래스
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
}
}
당신이 한 일을 이해했다고 생각합니다. 고마워요. – Melky
감사합니다. 내 대답이 도움이 되었기 때문에 기쁩니다. – dbooth