private void DeleteClick([NotNull] object sender, [NotNull] RoutedEventArgs e) { Debug.ArgumentNotNull(sender, nameof(sender)); Debug.ArgumentNotNull(e, nameof(e)); var selectedIndex = MacroList.SelectedIndex; var selectedItem = MacroList.SelectedItem as ListBoxItem; if (selectedItem == null) { return; } var macro = selectedItem.Tag as Macro; if (macro == null) { Trace.Expected(typeof(Macro)); return; } if (AppHost.MessageBox(string.Format(Rocks.Resources.MacroOrganizer_DeleteClick_Are_you_sure_you_want_to_delete__0__, macro.Text), Rocks.Resources.Confirmation, MessageBoxButton.OKCancel, MessageBoxImage.Question) != MessageBoxResult.OK) { return; } MacroManager.Delete(macro); MacroList.Items.Remove(selectedItem); selectedIndex--; if (selectedIndex < 0) { selectedIndex = 0; } if (selectedIndex < MacroList.Items.Count) { MacroList.SelectedIndex = selectedIndex; } var postSaveMacro = GetPostSaveMacroName(); if (MacroManager.Macros.FirstOrDefault(m => m.Text == postSaveMacro) == null) { SetPostSaveMacroName(string.Empty); PostSaveMacros.Items.Clear(); } EnableButtons(); }