public void DeleteLesson() { if (_lessons != null && _lessons.Count > 0 && IndexCurrentLesson >= 0 && IndexCurrentLesson < _lessons.Count) { var selectedLesson = Lessons[IndexCurrentLesson].Value.Name; // Removes from lesson collection Lessons.RemoveAt(IndexCurrentLesson); var tmpLessons = new ObservableCollection <KeyValuePair <int, MinimalLesson> >(); foreach (var lesson in Lessons) { if (lesson.Key > IndexCurrentLesson) { tmpLessons.Add(new KeyValuePair <int, MinimalLesson>(lesson.Key - 1, lesson.Value)); } else { tmpLessons.Add(lesson); } } Lessons = tmpLessons; RaisePropertyChanged("Lessons"); // Remove from HDD var directory = Data.GetLessonFolder(selectedLesson); if (Directory.Exists(directory)) { try { Directory.Delete(directory, true); } catch (IOException e) { MessageBox.Show(e.Message); } } RaisePropertyChanged("Lessons"); } }