private void ModClick(object sender, RoutedEventArgs e) { if (StudentListBox.SelectedItem == null) { return; } // problémás verzió: //Student stud = StudentListBox.SelectedItem as Student; //StudentBindingWindow window = new StudentBindingWindow(stud); //if (window.ShowDialog() == true) MessageBox.Show("OK, modified"); //else MessageBox.Show("BUG: cannot cancel a BINDING!!!"); // TODO: edit a copy => Prototype design pattern! // javított verzió Student stud = StudentListBox.SelectedItem as Student; Student clone = new Student(); clone.CopyFrom(stud); StudentBindingWindow window = new StudentBindingWindow(clone); // !! clone = nem baj ha elveszik if (window.ShowDialog() == true) { MessageBox.Show("OK, modified"); stud.CopyFrom(clone); // visszamásolni } StudentListBox.Items.Refresh(); // később observable collection... }
private void AddClick(object sender, RoutedEventArgs e) { StudentBindingWindow sbw = new StudentBindingWindow(); #region datacontext állítás (A) verzió: //Student s = new Student(); //sbw.DataContext = s; //if (sbw.ShowDialog() == true) // modális megjelenítés // StudentListBox.Items.Add(s); #endregion #region datacontext állítás (B) verzió: if (sbw.ShowDialog() == true) // modális megjelenítés { StudentListBox.Items.Add(sbw.Student); } #endregion }