# Suggestion Controls

> Configure SuggestionList and SuggestionDictionaryComboBox of the WPF spell check dialog, and list CreateSuggestions results in a ListBox beside a TextControl.

- **Product:** TX Spell .NET for WPF
- **Section:** Documentation
- **Kind:** Topic
- **Path:** TX Spell .NET for WPF > User Interface > Suggestion Controls
- **3659 words**
- **Web URL:** https://docs.textcontrol.com/tx-spell-dotnet-wpf/user-interface/suggestions/
- **LLMs URL:** https://docs.textcontrol.com/tx-spell-dotnet-wpf/user-interface/suggestions/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-spell-dotnet-wpf/user-interface/suggestions/llms-full.txt

---

Suggestions are the words TX Spell .NET offers in place of a misspelled one. The user sees them in the list of the spell check dialog, at the top of the context menu, or in a control of your own that you fill. TX Spell .NET has no separate suggestion control to place in a window: you set up the lists of its dialog and menu, or you show suggestions in a standard `ListBox`. Each of these places is covered below, with what it shows and the properties that change it.

### Where Suggestions Appear

| Place | What you set | Covered in |
|---|---|---|
| **Suggestions** list of the spell check dialog | [SuggestionList](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-wpf-proofing/suggestionlist/llms-full.txt) | [The Suggestion List of the Dialog](#the-suggestion-list-of-the-dialog) |
| **Suggestions Dictionary** list of the dialog | [SuggestionDictionaryComboBox](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-wpf-proofing/suggestiondictionarycombobox/llms-full.txt) | [The Suggestions Dictionary List](#the-suggestions-dictionary-list) |
| Top of the context menu | The `maxSuggestions` parameter of `GetMenuItems` | [Suggestions in the Context Menu](#suggestions-in-the-context-menu) |
| A control of your own | `CreateSuggestions` or the `SpellingCorrectionUIProvider` | [Show Suggestions Beside the Editor](#show-suggestions-beside-the-editor) |

Which suggestions are found at all depends on the dictionaries: only a dictionary whose [IsGetSuggestionsEnabled](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-proofing/dictionary/isgetsuggestionsenabled-property/llms-full.txt) property is `true` provides suggestions. It is `true` by default, and the user changes it in the **Suggestions** column of the [Options Dialog](https://docs.textcontrol.com/tx-spell-dotnet-wpf/user-interface/options-dialog/#the-spell-checking-dictionaries-tab).

### The Suggestion List of the Dialog

The spell check dialog lists the suggestions for the current word below the sentence. The [SuggestionList](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-wpf-proofing/spellcheckdialog/suggestionlist-property/llms-full.txt) property of the `SpellCheckDialog` describes this list:

![The Spelling dialog over a RichTextBox with the misspelled word "sampke" and the suggestions sample, spake, smoke and samples in the Suggestions list.](https://docs.textcontrol.com/assets/img/tx-spell-dotnet-wpf/richtextbox-spelling-dialog.aaaa3b4d.webp)

| Property | Default | Effect |
|---|---|---|
| [MaxSuggestions](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-wpf-proofing/suggestionlist/maxsuggestions-property/llms-full.txt) | 10 | The largest number of suggestions in the list |
| [IsNoSuggestionsItemEnabled](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-wpf-proofing/suggestionlist/isnosuggestionsitemenabled-property/llms-full.txt) | `true` | When no suggestion is found, the list shows an item that says so |

Set them before the dialog opens, for example in the constructor of the window, where `txSpellChecker1` is the spell checker taken from the resources:

```csharp
SpellCheckDialog dialog = txSpellChecker1.SpellCheckDialog;

// Show the five best suggestions only
dialog.SuggestionList.MaxSuggestions = 5;

// Offer "All" in the Suggestions Dictionary list
dialog.SuggestionDictionaryComboBox.IsAllItemEnabled = true;
```

The second setting belongs to the list below the suggestions, described next.

### The Suggestions Dictionary List

**Suggestions Dictionary** chooses the dictionary the suggestions come from. With one dictionary, it shows that dictionary. With several, for example English and a dictionary of medical terms, the user switches between them, and the list of suggestions changes with the choice. The picture shows the list in TX Text Control Words, a Windows Forms application:

![The Spelling dialog over TX Text Control Words with the Suggestions Dictionary list open, offering en_US.dic and Shared Medical Dictionary.](https://docs.textcontrol.com/assets/img/tx-spell-dotnet-wpf/spelling-dialog-dict-list.87947a59.webp)

The [SuggestionDictionaryComboBox](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-wpf-proofing/spellcheckdialog/suggestiondictionarycombobox-property/llms-full.txt) property of the `SpellCheckDialog` describes this list:

| Property | Default | Effect |
|---|---|---|
| [IsAllItemEnabled](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-wpf-proofing/suggestiondictionarycombobox/isallitemenabled-property/llms-full.txt) | `false` | Adds an **All** item that takes suggestions from all dictionaries at once. It appears only when more than one dictionary provides suggestions |
| [IsAllItemSelected](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-wpf-proofing/suggestiondictionarycombobox/isallitemselected-property/llms-full.txt) | `false` | Whether **All** is selected |
| [SuggestionDictionary](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-wpf-proofing/suggestiondictionarycombobox/suggestiondictionary-property/llms-full.txt) |  | The selected [Dictionary](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-proofing/dictionary/llms-full.txt), or `null` when **All** is selected |

The list shows a dictionary by its file name, such as *en\_US.dic*, unless you give it a [DisplayName](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-proofing/dictionary/displayname-property/llms-full.txt). The picture shows "Shared Medical Dictionary" as the display name of a second dictionary. [Options Dialog](https://docs.textcontrol.com/tx-spell-dotnet-wpf/user-interface/options-dialog/#hide-or-rename-a-dictionary) sets one in code.

To open the dialog with suggestions from one dictionary, pass it to [Show](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-wpf-proofing/spellcheckdialog/show-method/llms-full.txt), as in `Show(textControl1, dictionary)`.

### Suggestions in the Context Menu

The context menu of a misspelled word starts with its suggestions. When you build the menu yourself with [GetMenuItems](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-wpf-proofing/txspellchecker/getmenuitems-method/llms-full.txt), its last parameter is the largest number of suggestions:

![The spell check menu of a TextControl with the suggestions sample, spake, smoke, samples and sampler at the top.](https://docs.textcontrol.com/assets/img/tx-spell-dotnet-wpf/textcontrol-context-menu.e3692bcd.webp)

The *Context menu strip* samples of the setup pass 5. When no suggestion is found, the menu shows an item of the type `NoSuggestions` in their place. [Context Menus](https://docs.textcontrol.com/tx-spell-dotnet-wpf/user-interface/context-menus/llms-full.txt) builds the whole menu.

### Show Suggestions Beside the Editor

A list next to the editor can show the suggestions for the word at the input position while the user types, without a right-click. A double-click on a suggestion replaces the word. In a new WPF project with the TX Text Control and TX Spell .NET packages, replace the contents of *MainWindow.xaml*, and change `SpellingApp` to the namespace of your project:

```xml
<Window x:Class="SpellingApp.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:tx="clr-namespace:TXTextControl.WPF;assembly=TXTextControl.WPF"
        xmlns:spell="clr-namespace:TXTextControl.WPF.Proofing;assembly=TXSpell.WPF"
        Title="Suggestions" Height="450" Width="800">
    <Window.Resources>
        <spell:TXSpellChecker x:Key="txSpellChecker1" />
    </Window.Resources>
    <DockPanel>
        <ListBox Name="suggestionList" DockPanel.Dock="Right" Width="180"
                 MouseDoubleClick="SuggestionList_MouseDoubleClick" />
        <tx:TextControl Name="textControl1"
                        IsSpellCheckingEnabled="True"
                        SpellChecker="txSpellChecker1"
                        InputPositionChanged="TextControl1_InputPositionChanged" />
    </DockPanel>
</Window>
```

Then replace the contents of *MainWindow.xaml.cs*:

```csharp
using System;
using System.Windows;
using System.Windows.Input;
using TXTextControl;
using TXTextControl.Proofing;
using TXTextControl.WPF.Proofing;

namespace SpellingApp
{
    public partial class MainWindow : Window
    {
        private readonly TXSpellChecker txSpellChecker1;

        public MainWindow()
        {
            InitializeComponent();
            txSpellChecker1 = (TXSpellChecker)FindResource("txSpellChecker1");
        }

        private void TextControl1_InputPositionChanged(object sender, EventArgs e)
        {
            suggestionList.Items.Clear();

            // The misspelled word at the input position
            MisspelledWord word = textControl1.MisspelledWords.GetItem();
            if (word == null || textControl1.Selection.Start < word.Start - 1
                || textControl1.Selection.Start > word.Start + word.Length - 1)
            {
                return;
            }

            txSpellChecker1.CreateSuggestions(word.Text, 6);
            foreach (Suggestion suggestion in txSpellChecker1.Suggestions)
            {
                suggestionList.Items.Add(suggestion.Text);
            }
        }

        private void SuggestionList_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            if (suggestionList.SelectedItem == null) return;

            // Replace the misspelled word with the chosen suggestion
            textControl1.MisspelledWords.Remove(textControl1.MisspelledWords.GetItem(), suggestionList.SelectedItem.ToString());
            textControl1.Focus();
        }
    }
}
```

Run the application and type a misspelled word: its suggestions appear in the list on the right.

The code works as follows:

- The [InputPositionChanged](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/inputpositionchanged-event/llms-full.txt) event of the `TextControl` updates the list whenever the input position moves.
- [GetItem](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/misspelledwordcollection/getitem-method/llms-full.txt) without a parameter returns the misspelled word at the input position from the [MisspelledWords](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/misspelledwords-property/llms-full.txt) collection, or the next one when there is none. The comparison with [Selection.Start](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/selection/start-property/llms-full.txt) leaves the list empty when the input position is not in the word or directly in front of or behind it. `Selection.Start` counts from 0 and `Start` of the word from 1.
- [CreateSuggestions](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-wpf-proofing/txspellchecker/createsuggestions-method/llms-full.txt) creates at most six suggestions for the word and stores them in [Suggestions](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-wpf-proofing/txspellchecker/suggestions-property/llms-full.txt), a collection of [Suggestion](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-proofing/suggestion/llms-full.txt) objects with a [Text](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-proofing/suggestion/text-property/llms-full.txt).
- [Remove](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/misspelledwordcollection/remove-method/llms-full.txt) of the `MisspelledWords` collection replaces the word with the chosen suggestion.

[Incorrect Words and Suggestions](https://docs.textcontrol.com/tx-spell-dotnet-wpf/spell-checking/suggestions/llms-full.txt) explains `CreateSuggestions` and its overloads in detail.

### Bind a List to the Correction Provider

For a correction panel that works through the misspelled words one by one, like the dialog, bind a `ListBox` to the [SpellingCorrectionUIProvider](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-proofing/spellingcorrectionuiprovider/llms-full.txt) in XAML. Its [Suggestions](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-proofing/spellingcorrectionuiprovider-suggestionshandler/suggestions-property/llms-full.txt) always hold the suggestions for the current word, and its [SuggestionDictionariesHandling](https://docs.textcontrol.com/tx-spell-dotnet-wpf/reference/txtextcontrol-proofing/spellingcorrectionuiprovider/suggestiondictionarieshandling-property/llms-full.txt) fills a list of dictionaries like the one of the dialog. The list updates through data binding, without event handlers of yours. [Spelling Correction Modes and UI Provider](https://docs.textcontrol.com/tx-spell-dotnet-wpf/spell-checking/correction-modes/llms-full.txt) builds such a panel.

### Next Steps

- [Incorrect Words and Suggestions](https://docs.textcontrol.com/tx-spell-dotnet-wpf/spell-checking/suggestions/llms-full.txt): create suggestions in code.
- [Context Menus](https://docs.textcontrol.com/tx-spell-dotnet-wpf/user-interface/context-menus/llms-full.txt): the menu with the suggestions at the top.
- [Customizing the Spell Check Dialog](https://docs.textcontrol.com/tx-spell-dotnet-wpf/user-interface/customizing-dialog/llms-full.txt): change the buttons, the font and the preview of the dialog.
- [Loading and Managing Dictionaries](https://docs.textcontrol.com/tx-spell-dotnet-wpf/dictionaries/managing/llms-full.txt): add the dictionaries that suggestions come from.

---

## Nearby

- **Previous:** [Context Menus](https://docs.textcontrol.com/tx-spell-dotnet-wpf/user-interface/context-menus/llms-full.txt)
- **Next:** [Localization and Resource Kit](https://docs.textcontrol.com/tx-spell-dotnet-wpf/user-interface/localization/llms-full.txt)
