TestAPI
CoreMVVM
XamlPadX
Xaml Compliance
One of the interesting features in Editing is the speller and it works really well. :) One of the ineteresting scenarios when it comes to speller is to add the speller choices to a custom context menu. The speller choices would have to be added in the ContextMenuOpening event handler as below:
spellingError = textBox.GetSpellingError(caretIndex); if (spellingError != null){ foreach (string str in spellingError.Suggestions) { MenuItem mi = new MenuItem(); mi.Header = str; mi.FontWeight = FontWeights.Bold; mi.Command = EditingCommands.CorrectSpellingError; mi.CommandParameter = str; mi.CommandTarget = textBox; textBox.ContextMenu.Items.Insert(cmdIndex, mi); cmdIndex++; } Separator separatorMenuItem1 = new Separator(); textBox.ContextMenu.Items.Insert(cmdIndex, separatorMenuItem1); cmdIndex++; MenuItem ignoreAllMI = new MenuItem(); ignoreAllMI.Header = "Ignore All"; ignoreAllMI.Command = EditingCommands.IgnoreSpellingError; ignoreAllMI.CommandTarget = textBox; textBox.ContextMenu.Items.Insert(cmdIndex, ignoreAllMI); cmdIndex++; Separator separatorMenuItem2 = new Separator(); textBox.ContextMenu.Items.Insert(cmdIndex, separatorMenuItem2);}
spellingError = textBox.GetSpellingError(caretIndex);
{
MenuItem mi =
mi.Header = str;
mi.FontWeight = FontWeights.Bold;
mi.Command = EditingCommands.CorrectSpellingError;
mi.CommandParameter = str;
mi.CommandTarget = textBox;
textBox.ContextMenu.Items.Insert(cmdIndex, mi);
cmdIndex++;
}
Separator separatorMenuItem1 =
textBox.ContextMenu.Items.Insert(cmdIndex, separatorMenuItem1);
MenuItem ignoreAllMI =
ignoreAllMI.Header =
ignoreAllMI.Command = EditingCommands.IgnoreSpellingError;
ignoreAllMI.CommandTarget = textBox;
textBox.ContextMenu.Items.Insert(cmdIndex, ignoreAllMI);
Separator separatorMenuItem2 =
textBox.ContextMenu.Items.Insert(cmdIndex, separatorMenuItem2);
Thats all there is to it. Its the same for RichTextBox except for the first line where you get the spellingError - rtb.GetSpellingError(rtb.CaretPosition)
The complete sample code is attached so that you can see it working in all glory :)..
Hi...
What do i ned to do similarly for adding the word to dictionary... like the 'Add To Dictionary' option in word.
please reply back to ramanujamsampath@gmail.com
currently we do not support it in V1