Adding Spell Checking
In this topic you'll add spell-checking to your application. This topic assumes you have added a C1RichTextBox control and a C1RichTextBoxToolbar control to your page and linked the two together. If you currently click the Spell Check button in the toolbar at run time, you'll receive a message that spell checking is currently not set up. In this step you'll add a dictionary and set up spell-checking.
Complete the following steps:
1. In the Solution Explorer, right-click the .Web project and select Add | Existing Item. The Add Existing Item dialog box will appear.
2. In the Add Existing Item dialog box locate the C1Spell_en-US.dct file included in the RichTextBoxSamples sample folder. By default, it should be installed in the Documents or My Documents folder in ComponentOne Samples\Studio for Silverlight 4.0\C1.Silverlight.RichTextBox\RichTextBoxSamples\RichTextBoxSamples.Web.
This is a US English dictionary file – if you add another file, instead, you can adapt the steps below with the appropriate code.
3. In the Solution Explorer, right-click the MainPage.xaml file and select View Code to open the code file.
4. In the Code Editor, add the following code to import the following namespaces:
Imports C1.Silverlight.RichTextBox
Imports C1.Silverlight.SpellChecker
•C#
using C1.Silverlight.RichTextBox;
using C1.Silverlight.SpellChecker;
5. Add code to the MainPage constructor so that it appears similar to the following:
Public Sub New()
InitializeComponent()
Dim spell As New C1SpellChecker()
spell.MainDictionary.LoadAsync("C1Spell_en-US.dct")
Me.C1RichTextBox.SpellChecker = spell
End Sub
•C#
public MainPage()
{
InitializeComponent();
var spell = new C1SpellChecker();
spell.MainDictionary.LoadAsync("C1Spell_en-US.dct");
this.c1RichTextBox.SpellChecker = spell;
}
This code adds spell-checking – including as-you-type spell-checking – to the application.
What You've Accomplished
In this step you added spell-checking to your C1RichTextBox application. Type in the C1RichTextBox and notice that as-you-type spell-checking is initialized and misspelled words appear with a red line underneath. If you click the Spell Check button in the C1RichTextBoxToolbar, notice that the Spelling dialog box now appears.