private void MainDockPanel_KeyDown(object sender, KeyEventArgs e) { switch (e.Key) { case Key.F2: { AddGroupWindow ad = new AddGroupWindow(); if (ad.ShowDialog() == true) { Groups temp = ad.group; try { using (SmallBusinessDBEntities context = new SmallBusinessDBEntities()) { context.Groups.Add(temp); context.SaveChanges(); MessageBox.Show("Изменения сохранены"); groupList.Add(temp); GroupDataGrid.Items.Refresh(); } //using } //try catch (Exception ex) { MessageBox.Show(ex.Message); } //catch } //if } //case Key.F2 break; case Key.Escape: { this.Content = null; } //case Key.Escape break; default: break; } }