# Checking on Demand

> Open a spelling dialog from a WPF button: TextControl.SpellCheckDialog, SpellCheckDialog.Show for TX Text Control, and Check with Show(Window) for a TextBox.

- **Product:** TX Spell .NET for WPF
- **Section:** Documentation
- **Kind:** Topic
- **Path:** TX Spell .NET for WPF > Spell Checking > Checking on Demand
- **2577 words**
- **Web URL:** https://docs.textcontrol.com/tx-spell-dotnet-wpf/spell-checking/on-demand/
- **LLMs URL:** https://docs.textcontrol.com/tx-spell-dotnet-wpf/spell-checking/on-demand/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-spell-dotnet-wpf/spell-checking/on-demand/llms-full.txt

---

Many applications check spelling when the user asks for it: a **Spelling** button, a menu item, or a check before a document is saved or sent. The user then walks through the misspelled words one by one in a dialog, choosing a suggestion or ignoring the word each time. With TX Spell .NET for WPF, that dialog opens with one line of code, for TX Text Control as well as for a `TextBox` or any other control.

### Two Dialogs to Choose From

When a spell checker is connected to a `TextControl`, two spelling dialogs are available. Both walk through the same misspelled words; they differ in who opens them and whether you can change them:

|  | Dialog of TX Text Control | Dialog of TX Spell .NET |
|---|---|---|
| Opened by | [TextControl.SpellCheckDialog](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/spellcheckdialog-method/llms-full.txt), or **Spell Check Dialog...** in the context menu | [SpellCheckDialog.Show](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-wpf-proofing/spellcheckdialog/show-method/llms-full.txt) |
| Works with | TX Text Control only | TX Text Control and any other control |
| Can be customized | No, it is preconfigured | Yes: buttons, texts, font and behavior |
| Raises [MisspelledWordChanging](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-wpf-proofing/txspellchecker/misspelledwordchanging-event/llms-full.txt) for each change | No | Yes |

Choose the dialog of TX Text Control when the preconfigured one is all you need. Choose the dialog of TX Spell .NET to change it, to check several controls in one pass, or to check a control other than TX Text Control.

### Open the Dialog of TX Text Control

The `SpellCheckDialog` method of the `TextControl` steps through all misspelled words of the document: the main text first, then the headers, footers and text frames. It is available only when a spell checker is connected through the [SpellChecker](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/spellchecker-property/llms-full.txt) property, as [As-You-Type Checking](https://docs.textcontrol.com/tx-spell-dotnet-wpf/spell-checking/as-you-type/llms-full.txt) shows. Call it from a button or menu item:

```csharp
private void buttonSpelling_Click(object sender, RoutedEventArgs e)
{
    textControl1.SpellCheckDialog();
}
```

An overload takes the dictionary the dialog creates suggestions from. It is useful only when more than one dictionary has been added to the spell checker.

With the ribbon of TX Text Control, you don't need this code for the user to start a check. The **Proofing** tab, a [RibbonProofingTab](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/ribbonproofingtab/llms-full.txt) connected through the `RibbonProofingTab` property of the `TextControl`, holds the spelling and hyphenation buttons. They need a connected spell checker.

### Open the Dialog of TX Spell .NET

The [SpellCheckDialog](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-wpf-proofing/txspellchecker/spellcheckdialog-property/llms-full.txt) property of the [TXSpellChecker](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-wpf-proofing/txspellchecker/llms-full.txt) returns the dialog of TX Spell .NET, a [SpellCheckDialog](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-wpf-proofing/spellcheckdialog/llms-full.txt). To check a `TextControl`, pass it to `Show`. The spell checker is the resource declared in XAML, which the code-behind gets with `FindResource`, as [As-You-Type Checking](https://docs.textcontrol.com/tx-spell-dotnet-wpf/spell-checking/as-you-type/#use-the-spell-checker-in-code) shows:

```csharp
private void buttonSpelling_Click(object sender, RoutedEventArgs e)
{
    txSpellChecker1.SpellCheckDialog.Show(textControl1);
}
```

No further code is needed for TX Text Control: the dialog finds the misspelled words and applies the user's corrections to the document itself.

![The Spelling dialog over a TextControl: the sentence with the misspelled word "sampke" in red, the suggestions, the buttons Ignore Once, Ignore All, Add To Dictionary, Change and Change All, the Suggestions Dictionary en_US.dic, Options and Cancel.](https://docs.textcontrol.com/assets/img/tx-spell-dotnet-wpf/textcontrol-spelling-dialog.0a7b34fc.webp)

The dialog shows the misspelled word in its sentence, with the language of the word above it. The user picks a suggestion and clicks **Change** or **Change All**, or skips the word with **Ignore Once** or **Ignore All**. **Add To Dictionary** puts the word into a user dictionary, and the **Suggestions Dictionary** list chooses which dictionary the suggestions come from. [Spell Check Dialog](https://docs.textcontrol.com/tx-spell-dotnet-wpf/user-interface/spell-check-dialog/llms-full.txt) describes every part of it, and [Customizing the Spell Check Dialog](https://docs.textcontrol.com/tx-spell-dotnet-wpf/user-interface/customizing-dialog/llms-full.txt) shows how to change it.

`Show` has four overloads:

| Overload | Checks |
|---|---|
| `Show(object textControl)` | The `TextControl` you pass |
| `Show(object textControl, Dictionary suggestionDictionary)` | The same, with suggestions from the [Dictionary](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-proofing/dictionary/llms-full.txt) you pass |
| `Show(Window owner)` | The words in [IncorrectWords](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-wpf-proofing/txspellchecker/incorrectwords-property/llms-full.txt), found by a call to `Check` before; `owner` is the window that owns the dialog |
| `Show(Window owner, Dictionary suggestionDictionary)` | The same, with suggestions from the dictionary you pass |

### Check a TextBox in the Dialog

Without a connected `TextControl`, the spell checker isn't initialized for you: call its [Create](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-wpf-proofing/txspellchecker/create-method/llms-full.txt) method once before the first check, for example in the constructor of the window.

The dialog can walk through the words of any text, but only TX Text Control applies the corrections itself. For another control, you find the words first and apply each correction yourself. A `TextBox` makes this simple, because its character positions are those of its `Text`:

1. Call [Check](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-wpf-proofing/txspellchecker/check-method/llms-full.txt) with the text of the control, then `Show(this)`. Don't call `Check` while the dialog is open: it throws an exception.

```csharp
private void buttonSpelling_Click(object sender, RoutedEventArgs e)
{
    txSpellChecker1.Check(textBox1.Text);
    txSpellChecker1.SpellCheckDialog.Show(this);
}
```

1. Handle the [IncorrectWordChanging](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-wpf-proofing/txspellchecker/incorrectwordchanging-event/llms-full.txt) event. It fires each time the user changes or deletes a word in the dialog, and your handler makes the same change in the control. Attach it once, after `FindResource` in the constructor, with `txSpellChecker1.IncorrectWordChanging += txSpellChecker1_IncorrectWordChanging;`:

```csharp
private void txSpellChecker1_IncorrectWordChanging(object sender, TXTextControl.Proofing.IncorrectWordChangingEventArgs e)
{
    // Select the word in the control
    textBox1.Select(e.IncorrectWord.Start, e.IncorrectWord.Length);

    if (e.Type == TXTextControl.Proofing.TXSpell.ChangeType.Replace)
    {
        textBox1.SelectedText = e.CorrectedWord;
    }
    else if (e.Type == TXTextControl.Proofing.TXSpell.ChangeType.Delete)
    {
        textBox1.SelectedText = "";
    }
}
```

1. Run the application and click the button. The dialog opens with the first misspelled word, and each correction appears in the `TextBox`.

The handler works as follows:

- [Type](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-proofing/incorrectwordchangingeventargs/type-property/llms-full.txt) says what the user did, as a value of [TXSpell.ChangeType](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-proofing/txspell-changetype/enumeration/llms-full.txt): `Replace`, `Delete` or `Ignore`. An ignored word needs no change in the text.
- [IncorrectWord](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-proofing/incorrectwordchangingeventargs/incorrectword-property/llms-full.txt) is the word being changed. Its `Start` and `Length` locate it in the text passed to `Check`; `Start` counts from 0, as `TextBox.Select` does.
- [CorrectedWord](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-proofing/incorrectwordchangingeventargs/correctedword-property/llms-full.txt) is the replacement the user chose. Read it only when `Type` is `Replace`: otherwise it throws an exception.

For a `RichTextBox`, pass the text of its document, `new TextRange(richTextBox1.Document.ContentStart, richTextBox1.Document.ContentEnd).Text`, to `Check`. The handler then has to find the `TextRange` of each word from its position in that text. The *RichTextBox\\SpellCheckDialog* sample of the setup does this. Because the text has no language set, the dialog shows "Language: No language set":

![The Spelling dialog over a RichTextBox, with the misspelled word "sampke" and the language line "No language set".](https://docs.textcontrol.com/assets/img/tx-spell-dotnet-wpf/richtextbox-spelling-dialog.aaaa3b4d.webp)

[Events](https://docs.textcontrol.com/tx-spell-dotnet-wpf/spell-checking/events/llms-full.txt) lists what else the handler's arguments carry, such as a `Cancel` property that stops the change.

### Control When the Dialog Closes

By default, the dialog closes when the last misspelled word is handled and tells the user in a message box that the check is complete. [Decide How a Check Ends](https://docs.textcontrol.com/tx-spell-dotnet-wpf/user-interface/spell-check-dialog/#decide-how-a-check-ends) shows the two properties that change this. To check several controls in one dialog, keep it open in the `SpellCheckDialogClosing` event, as [Checking Multiple Controls](https://docs.textcontrol.com/tx-spell-dotnet-wpf/spell-checking/multiple-controls/llms-full.txt) shows.

### Next Steps

- [Checking Multiple Controls](https://docs.textcontrol.com/tx-spell-dotnet-wpf/spell-checking/multiple-controls/llms-full.txt): walk through several editors with one dialog.
- [Checking Text Parts](https://docs.textcontrol.com/tx-spell-dotnet-wpf/spell-checking/text-parts/llms-full.txt): check only the headers, footers or text frames you choose.
- [Customizing the Spell Check Dialog](https://docs.textcontrol.com/tx-spell-dotnet-wpf/user-interface/customizing-dialog/llms-full.txt): add, remove and rename buttons.
- [Events](https://docs.textcontrol.com/tx-spell-dotnet-wpf/spell-checking/events/llms-full.txt): react to every change the dialog makes.

---

## Nearby

- **Previous:** [As-You-Type Checking](https://docs.textcontrol.com/tx-spell-dotnet-wpf/spell-checking/as-you-type/llms-full.txt)
- **Next:** [Incorrect Words and Suggestions](https://docs.textcontrol.com/tx-spell-dotnet-wpf/spell-checking/suggestions/llms-full.txt)
