/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void EditGrade_Click(object sender, RoutedEventArgs e) { bool exitCancel = false; bool normalExit = true; Window window = new Window() { Title = "Create grade", ResizeMode = ResizeMode.NoResize, WindowStartupLocation = WindowStartupLocation.CenterScreen }; window.Loaded += delegate(object o, RoutedEventArgs args) { if (_selectedEducationalLevel != null) { EducationalLevelType type = (_contentManager.GetComponent(_educationalLevelDictionary[_selectedEducationalLevel.Name]) as EducationalLevel).Level; GradeSelection grade = new GradeSelection(type) { VerticalAlignment = VerticalAlignment.Stretch, HorizontalAlignment = HorizontalAlignment.Stretch, }; window.Width = grade.Width + 35; window.Height = grade.Height + 40; window.Content = grade; grade.button.Click += delegate(object obj, RoutedEventArgs Args) { GradeSelection control = window.Content as GradeSelection; long id = _gradesDictionary[_selectedGrade.Name]; string icon = control.GetSelectedIcon(); GradeType gradeType = control.GetSelectedGrade(); if (icon != "") { if (_selectedEducationalLevel != null) { if (!ExistingGrade(_selectedGrade.Name)) { _contentManager.EditGrade(id, icon, gradeType); _selectedGrade.Source = new BitmapImage(new Uri(icon)); exitCancel = false; normalExit = false; window.Close(); } else { MessageBox.Show("Grade already exists!"); exitCancel = true; normalExit = true; } } } }; } else { window.Close(); } }; window.Closing += delegate(object o, CancelEventArgs args) { if (!normalExit) { if (exitCancel) { args.Cancel = true; } } }; window.ShowDialog(); }