Context Menus
Most users correct a misspelled word without leaving the text: they right-click the underlined word and choose the right spelling from a menu. With TX Text Control, TX Spell .NET provides this menu without any code. When you need other items in it, or a menu for another control, you declare your own ContextMenu and fill it with ready-made menu items. The sections below cover the built-in menu, how to replace it and how to react to its items.
Add the Spelling Items
A menu of your own also needs the suggestions for the word and the commands that correct it. GetMenuItems creates them for a misspelled word: its suggestions, Ignore, Ignore All and Add To Dictionary. Each item carries out its action when it is clicked, so you only add the items to the menu. The TextControl\Context menu strip sample of the setup builds its menu this way:

For a misspelled word of the TextControl, a MisspelledWord, the call takes the word, the TextControl and the largest number of suggestions:
TXTextControl.WPF.Proofing.MenuItem[] items = txSpellChecker1.GetMenuItems(misspelledWord, textControl1, 5);
It returns MenuItem objects, which are WPF MenuItem objects, so you add them to the Items of the ContextMenu together with items of your own. GetMenuItems doesn't create Spell Check Dialog... and Options...; those are items like the two in the XAML above. The sample of the setup shows the complete menu; Spell Checking Examples lists it.
What the Items Do
The Type of each MenuItem is a value of TXSpell.MenuItemType, and it decides what a click does:
| Type | What a click does |
|---|---|
Suggestion | Replaces the misspelled word with the text of the item |
IgnoreOnce | Ignores this occurrence of the word |
IgnoreAll | Ignores every occurrence of the word |
AddToDictionary | Adds the word to all editable user dictionaries |
Delete | Removes the word from the text |
NoSuggestions | Nothing; the item says that no suggestions were found |
After each click, the MenuItemClicked event of the TXSpellChecker reports the item, for example to log words that users add:
txSpellChecker1.MenuItemClicked += (sender, e) =>
{
if (e.MenuItem.Type == TXSpell.MenuItemType.AddToDictionary)
{
statusText.Text = "Word added to the dictionary.";
}
};
MenuItem of the MenuItemClickedEventArgs is the clicked item. statusText stands for a TextBlock of your window, and TXSpell needs using TXTextControl.Proofing;. Events lists the other events a correction raises.
Next Steps
- Synonyms in the Context Menu: offer synonyms of a word from a menu.
- Spell Check Dialog: the dialog of TX Spell .NET that the menu can open.
- Options Dialog: the dialog behind Options....
- Localization and Resource Kit: the texts of TX Spell .NET in other languages.
- Events: react to the corrections made in the menu.

