private void DeleteNotebook(INotebook nb) { if (nb.State == NotebookState.New || System.Windows.MessageBox.Show("Are you sure you wish to remove the notebook: '" + nb.Title + "'?", "OP.Notes", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { nb.BeforeSave -= notebook_BeforeSave; nb.AfterSave -= notebook_AfterSave; _notebooks.Remove(nb); nb.Delete(); var li = lbNotebooks.Items.OfType <ListBoxItem>().First(ti => ((ucNotebook)ti.Tag).Notebook == nb); var ctrlNb = (ucNotebook)li.Tag; if (pnlNotebooks.Children.Contains(ctrlNb)) { pnlNotebooks.Children.Remove(ctrlNb); } lbNotebooks.Items.Remove(li); } }