# Spell Checking and Hyphenation

> Spell checking in a WPF TextControl: declare a TXSpellChecker resource in XAML, plug in your own checker with SpellCheckText and adjust HyphenateWord.

- **Product:** TX Text Control .NET for WPF
- **Section:** Documentation
- **Kind:** Topic
- **Path:** TX Text Control .NET for WPF > Document Editor > Spell Checking and Hyphenation
- **2278 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/spell-checking/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/spell-checking/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/spell-checking/llms-full.txt

---

Red zigzag lines under misspelled words, suggestions on a right-click and hyphens at the ends of lines: the WPF `TextControl` displays all of this, but the knowledge of words comes from a spell checker. That is TX Spell .NET for WPF, a separate product of Text Control with its own documentation, or a checker of your own that your code connects through an event. Here you find the members of TX Text Control involved, the XAML that connects TX Spell .NET, and the links into its documentation.

The samples work in a window with a `TextControl` named `textControl1`, as built in [Create Your First WPF Application](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/getting-started/document-editor/first-application/llms-full.txt).

### What the User Sees

Once a spell checker is connected and checking is on, words are checked as they are typed, and misspelled ones are underlined in red. Right-clicking one shows suggestions and the commands **Ignore**, **Ignore All**, **Add To Dictionary**, **Spell Check Dialog...** and **Options...**:

![A WPF TextControl with misspelled words underlined in red in the header and the main text, and a context menu with the suggestions sample, spake, smoke, samples and sampler above the commands Ignore, Ignore All and Add To Dictionary.](https://docs.textcontrol.com/assets/img/tx-text-control-dotnet-wpf/spell-check-context-menu.e3692bcd.webp)

In a ribbon, the **Proofing** tab, a [RibbonProofingTab](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/ribbonproofingtab/llms-full.txt), turns spell checking and hyphenation on and off, opens the thesaurus and the spelling dialog, and loads dictionaries. The `TextControl` finds the tab by the name in its [RibbonProofingTab](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/ribbonproofingtab-property/llms-full.txt) property.

The spelling dialog shows the misspelled word in its sentence, the language, the suggestions of the selected dictionary and the buttons **Ignore Once**, **Ignore All**, **Add To Dictionary**, **Change**, **Change All** and **Options...**:

![The WPF Spelling dialog box over a TextControl, with the misspelled word sampke in red, the suggestions sample, spake, smoke and samples, the suggestions dictionary en_US.dic and the buttons to ignore, add and change the word.](https://docs.textcontrol.com/assets/img/tx-text-control-dotnet-wpf/spelling-dialog.0a7b34fc.webp)

### What TX Text Control Provides

These members of the WPF `TextControl` work with the spell checker:

- **[SpellChecker](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/spellchecker-property/llms-full.txt)** connects the spell checker. In WPF, it is a string: the key of a `TXSpellChecker` resource in the resources of the control or of one of its parents, such as the window. An empty string disconnects it.
- **[IsSpellCheckingEnabled](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/isspellcheckingenabled-property/llms-full.txt)** turns checking as the user types on and off.
- **[SpellCheckDialog](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/spellcheckdialog-method/llms-full.txt)** opens the built-in spelling dialog, which goes through the main text, then the headers, footers and text frames.
- **[SpellCheckContextMenu](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/spellcheckcontextmenu-property/llms-full.txt)** chooses the menu of a misspelled word: `(Default)` for the built-in one, `(none)` for none, or the resource key of a `ContextMenu` of your own.
- **[MisspelledWords](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/misspelledwords-property/llms-full.txt)** returns the misspelled words of the text part with the input focus, as [MisspelledWord](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/misspelledword/llms-full.txt) objects.
- **[IsHyphenationEnabled](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/ishyphenationenabled-property/llms-full.txt)** divides the last word of a full line, and the **[HyphenateWord](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/hyphenateword-event/llms-full.txt)** event lets your code change where.
- **[IsLanguageDetectionEnabled](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/islanguagedetectionenabled-property/llms-full.txt)** gives text without a language the one TX Spell .NET detects, and **[LanguageDialog](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/languagedialog-method/llms-full.txt)** lets the user set the language of the selection, which chooses the dictionary.
- **[SpellCheckText](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/spellchecktext-event/llms-full.txt)** hands new text to a spell checker of your own when no `SpellChecker` is connected.

### Connect TX Spell .NET

TX Spell .NET for WPF has its own setup, license and NuGet package, `TXTextControl.TXSpell.WPF.SDK`. Its `TXSpellChecker` is declared as a resource of the window, and `SpellChecker` names its key; the `TextControl` initializes the connected spell checker itself. [Connect the Spell Checker in XAML](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/integration/tx-spell/#connect-the-spell-checker-in-xaml) shows the complete XAML with the namespace declaration and a **Proofing** tab.

[Integrating TX Spell .NET for WPF](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/integration/tx-spell/llms-full.txt) also installs and licenses both products, shares one spell checker among several editors and deploys the application. The [TX Spell .NET for WPF](https://docs.textcontrol.com/tx-spell-dotnet-wpf/llms-full.txt) documentation describes dictionaries, hyphenation lists, the spelling dialog and the context menus.

### Use Another Spell Checker

If `SpellChecker` is empty and `IsSpellCheckingEnabled` is `True`, the `TextControl` raises [SpellCheckText](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/spellchecktext-event/llms-full.txt) each time text has changed. Your handler checks the text and returns the misspelled words, which the editor underlines. Connect it with `SpellCheckText="TextControl1_SpellCheckText"` on the `TextControl` element. The following handler reports each occurrence of *teh*:

```csharp
private void TextControl1_SpellCheckText(object sender, SpellCheckTextEventArgs e)
{
    List<MisspelledWord> misspelledWords = new List<MisspelledWord>();

    // Find the words with your spell checker; here, one known typo
    int index = e.Text.IndexOf("teh");

    while (index >= 0)
    {
        // MisspelledWord positions are one-based
        misspelledWords.Add(new MisspelledWord(index + 1, 3));
        index = e.Text.IndexOf("teh", index + 3);
    }

    e.MisspelledWords = misspelledWords.ToArray();
}
```

What the code does:

- [Text](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/spellchecktexteventargs/text-property/llms-full.txt) of the [SpellCheckTextEventArgs](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/spellchecktexteventargs/llms-full.txt) is the text to check, and [Culture](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/spellchecktexteventargs/culture-property/llms-full.txt) its language.
- Each [MisspelledWord](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/misspelledword/constructor/llms-full.txt) takes the one-based position of the word in `Text` and its length.
- Setting [MisspelledWords](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/spellchecktexteventargs/misspelledwords-property/llms-full.txt) hands the result to the editor.

`SpellCheckTextEventArgs` and `MisspelledWord` are in the `TXTextControl` namespace, and `List<T>` needs `using System.Collections.Generic;` unless implicit usings are on. The built-in spelling dialog and the suggestion menu require a connected `SpellChecker`, so with your own checker, your application provides that user interface.

### Control Where Words Are Divided

When hyphenation is on and a word doesn't fit into the line, [HyphenateWord](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/hyphenateword-event/llms-full.txt) occurs with [HyphenateWordEventArgs](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/hyphenatewordeventargs/llms-full.txt):

| Property | Value |
|---|---|
| [Word](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/hyphenatewordeventargs/word-property/llms-full.txt), [Culture](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/hyphenatewordeventargs/culture-property/llms-full.txt) | The word to hyphenate and its language |
| [DividePos](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/hyphenatewordeventargs/dividepos-property/llms-full.txt) | The division calculated by TX Spell .NET, or 0 without a spell checker; the handler can change it |
| [MaxDividePos](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/hyphenatewordeventargs/maxdividepos-property/llms-full.txt) | How many characters of the word still fit into the line |

The word is divided at `DividePos` if that isn't greater than `MaxDividePos`. With `HyphenateWord="TextControl1_HyphenateWord"` on the `TextControl` element, the following handler keeps short words in one piece:

```csharp
private void TextControl1_HyphenateWord(object sender, HyphenateWordEventArgs e)
{
    // Don't divide words of fewer than seven characters
    if (e.Word.Length < 7)
    {
        e.DividePos = 0;
    }
}
```

### Next Steps

- [TX Spell .NET for WPF](https://docs.textcontrol.com/tx-spell-dotnet-wpf/llms-full.txt): the documentation of the spell checker.
- [Built-in Ribbon Tabs](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/ribbon-ui/ribbon/llms-full.txt): the **Proofing** tab among the other tabs.
- [Context Menus](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/ribbon-ui/context-menus/llms-full.txt): the other context menus of the editor.
- [Events](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/events/llms-full.txt): event handlers in XAML and code.

---

## Nearby

- **Previous:** [Document Protection and Editable Regions](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/protection/llms-full.txt)
- **Next:** [Viewing, Zooming, and Navigation](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/viewing/llms-full.txt)
