private void MainTextBox_ContextMenuOpening(object sender, ContextMenuEventArgs e) { MainTextBox.ContextMenu.Items.Clear(); SpellingError spellingError = MainTextBox.GetSpellingError(MainTextBox.CaretPosition); if (spellingError != null && spellingError.Suggestions.Count() > 0) { foreach (string suggestion in spellingError.Suggestions) { MenuItem menuItem = new MenuItem(); menuItem.Header = suggestion; menuItem.FontWeight = FontWeights.Bold; menuItem.Command = EditingCommands.CorrectSpellingError; menuItem.CommandParameter = suggestion; menuItem.CommandTarget = MainTextBox; MainTextBox.ContextMenu.Items.Add(menuItem); } } else if (spellingError != null) { MenuItem menuItem = new MenuItem(); menuItem.Header = "No Suggestions"; menuItem.IsEnabled = false; MainTextBox.ContextMenu.Items.Add(menuItem); } if (spellingError != null) { Separator separator = new Separator(); MainTextBox.ContextMenu.Items.Add(separator); MenuItem addToDictionary = new MenuItem(); addToDictionary.Header = "Add to Dictionary"; var tr = MainTextBox.GetSpellingErrorRange(MainTextBox.CaretPosition); addToDictionary.Click += (object o, RoutedEventArgs args) => { _spellcheckDictionary.AddToDictionary(tr.Text); }; MainTextBox.ContextMenu.Items.Add(addToDictionary); } else { e.Handled = true; } }