The sample project Custom SpellCheckDialog shows how to create a fully operational spell check dialog. Its functionality is completely based on the SpellingCorrectionUIProvider methods and properties that were introduced by the previous articles Simple spelling correction user interface and Advanced spelling correction user interface.
The major differences to these samples lie in connecting the TextControl before opening the dialog, handling a preview where to correct manually the current misspelled word, changing the functionality of a button depending on the StateManager.Mode and implementing a Button to open the OptionsDialog.
In the following, the underlying concepts behind these issues are described, but it won't give any further explanation in code details. Therefore, we ask you to explore the Custom SpellCheckDialog sample more closely by yourself.
Connecting the TextControl before opening the dialog
The principal task of a spell check dialog is to correct the current misspelled words one by one with a correction supporting user interface. But opening such a dialog makes only sense, if the TextControl actually contains misspelled words. To prevent an unnecessary initializing of the spell check dialog, the TextControl should be first connected with the SpellingCorrectionUIProvider to determine its mode. If it is set to SpellingCorrectionMode.NoWordsToCorrectFound, the dialog won't be opened and a MessageBox informs the user that the TextControl does not contain any misspelled words. Whether or not the dialog is shown, the SpellingCorrectionUIProvider should be reset to its initial state by using the StateManager.Cancel method.
Handling a preview
Most spell check dialogs provide a preview that gives the user an opportunity to correct the current misspelled word manually. Such an editor usually shows the sentence where the misspelled word is located and highlights it in red color. Additionally, on starting editing inside the preview, the rest of the dialog changes to an editing mode, where most buttons and controls are disabled and the 'Ignore' button is changed to an 'Undo Edit' button.
To implement this behavior, the SpellingCorrectionUIProvider provides the StateManager.IsWordToCorrectEditing property that changes the current mode to SpellingCorrectionMode.WordToCorrectEditing. In this case, bound Button's and Control's are disabled, except the 'Change' and 'Change All' buttons. However, in this example, the Clicked events of these two buttons won't commit the selected suggestion of the suggestion ListBox anymore, but the modified misspelled word from the preview editor as the change parameter. Furthermore, to give the user the chance to cancel misspelled word editing using the preview, the 'Ignore' button is changed to an 'Undo Edit' button, where its Clicked event sets the StateManager.IsWordToCorrectEditing to false. The preview itself is updated on every current misspelled word change or use of the 'Undo Edit' button.
Changing the functionality of a button
There are to cases where the functionality of a button can be changed. The first one, as described above, is when the 'Ignore' needs to be an 'Undo Edit' button. The other one is when the misspelled word is a duplicated word. In this case the 'Change' button becomes a 'Delete' button and its Clicked event calls the CorrectionHandler.Delete method instead the CorrectionHandler.Change method.
Open an OptionsDialog
In most spell check dialogs, the user can change some spelling settings, by opening an options dialog. To adopt any changes by these modifications, the connected TextControl must be spell checked again on closing the options dialog. The StateManager.IsOptionsSettings property supports that behavior: Before opening the options dialog, it must be set to true, to save any prior ignore operations. When the dialog is closed, the property is set to false, which leads to a spell check of the TextControl and a resetting of the stored, ignored words.