RichTextBox for WinRT
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 C1RichTextBoxMenu control to your page.

In this help topic, you'll use an English dictionary resource. If you wish to use a different dictionary, you may choose any from the 22 supported dictionaries: http://www.componentone.com/SuperProducts/RichTextBoxWinRT/Dictionaries/

The main steps for adding spell-checking are to declare a new C1SpellChecker, load the Main Dictionary of your choice, and to assign C1SpellChecker to the SpellChecker property of your C1RichTextBox.

  1. Edit the C1RichTextBox and C1RichTextBoxMenu controls to reflect the following:
XAML Markup
Copy Code
<c1RTB:C1RichTextBoxMenu x:Name="rtbMenu" RichTextBox="{Binding ElementName=rtb}"/>
   <c1RTB:C1RichTextBox x:Name="rtb"  BorderThickness="2" BorderBrush="DarkGray" />
  1. In the Solution Explorer, right-click your application's name and select Add | New Folder. Name the folder Resources.
  2. In the Solution Explorer, right-click the Resources folder and select Add | Existing Item. The Add Existing Item dialog box will appear.
  3. 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\WinRT XAML Phone\C1.Xaml.RichTextBox\CS\RichTextBoxSamples\Resources.

This is a US English dictionary file – if you add another file, instead, you can adapt the steps below with the appropriate code.

  1. In the Properties window, set the C1Spell_en-US.dct file's Build Action to Embedded Resource.
  2. Right-click your MainPage.xaml page and select View Code from the context menu.
  3. Add the following import statements to the top of the page:
C#
Copy Code
 using C1.Xaml.SpellChecker;
 using C1.Xaml.RichTextBox;
  1.  Set the Text property in the MainPage() constructor:
C#
Copy Code
rtb.Text = @"Some facts about Mark Twain (spelling errors intentional ;-) A steambat pilot neded a vast knowldege of the ever-chaging river to be able to stop at any of the hundreds of ports and wood-lots along the river banks. Twain meticulosly studied 2,000 miles (3,200 km) of the Mississipi for more than two years before he received his steamboat pilot license in 1859.";
  1.  Declare a new C1SpellChecker:
C#
Copy Code
var spell = new C1SpellChecker();
  1. Assign C1SpellChecker to the SpellChecker property of your C1RichTextBox control:
C#
Copy Code
 rtb.SpellChecker = spell;
  1. Obtain the stream to your resource file. Make sure you insert your application name where indicated:
C#
Copy Code
Assembly asm = typeof(MainPage).GetTypeInfo().Assembly;
Stream stream = asm.GetManifestResourceStream("YourApplicationName.Resources.C1Spell_en-US.dct");
  1. Load the MainDictionary of your choice:
C#
Copy Code
spell.MainDictionary.Load(stream);

What You've Accomplished

In this topic, you added text to your C1RichTextBox control, and then added some code to handle spell-checking.

 

 


Copyright (c) GrapeCity, inc. All rights reserved.

Product Support Forum  |  Documentation Feedback