private void ClassList_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (e.AddedItems.Count > 0) { ListViewItem item = (ListViewItem)e.AddedItems.First(); String name = (String)item.Content; foreach (var course in classList) { String content = "Session " + course.SessionNumber; if (content.Equals(name)) { selectedClass = course; break; } } List <string> topics = selectedClass.Topics; topicsList.Items.Clear(); foreach (string topic in topics) { ComboBoxItem topicDispaly = new ComboBoxItem(); topicDispaly.Content = topic; topicsList.Items.Add(topicDispaly); } } }
private async void AddClass_Click(object sender, RoutedEventArgs e) { if (check() == 1) { return; } selectedClass = new CourseInfo(); selectedClass.Date = datePicker.Date.Date; selectedClass.Start = startTime.Time; selectedClass.End = endTime.Time; if (selectedStudent.ClassList.Count > 0) { selectedClass.SessionNumber = selectedStudent.ClassList.Last().SessionNumber + 1; } else { selectedClass.SessionNumber = 1; } selectedStudent.ClassList.Add(selectedClass); MemoryStream stream = new MemoryStream(); serializer.Serialize(stream, selectedStudent); string result = System.Text.Encoding.UTF8.GetString(stream.ToArray(), 0, stream.ToArray().Length); await WriteDataToFileAsync(selectedStudent.StudentName + ".S", result); ListViewItem selectedItem = null; foreach (ListViewItem item in StudentList.Items) { String text = (String)item.Content; if (text.Equals(selectedStudent.StudentName)) { selectedItem = item; break; } } ClassList.Items.Clear(); loadClassList(); }