Back to Devexpress

SpellingExtensions Class

wpf-devexpress-dot-xpf-dot-spellchecker-0a86eb8b.md

latest3.0 KB
Original Source

SpellingExtensions Class

A base class for spell check extension methods.

Namespace : DevExpress.Xpf.SpellChecker

Assembly : DevExpress.Xpf.SpellChecker.v25.2.dll

NuGet Package : DevExpress.Wpf.SpellChecker

Declaration

csharp
public static class SpellingExtensions
vb
Public Module SpellingExtensions

Remarks

The SpellingExtensions class provides extensiton methods used to retrieve SpellChecker error commands.

The GetErrorOperationCommands method creates a list of SpellChecker commands. The list depends on the type of misspelling and current spellchecker operation mode.

Use the GetSpellCheckError method to invoke a custom context menu for misspelled words, as shown below:

xaml
<RichTextBox x:Name="richTextBox" PreviewMouseRightButtonUp="RichTextBox_PreviewMouseRightButtonUp">
    <RichTextBox.ContextMenu>
        <ContextMenu ItemsSource="{Binding Path=MenuItems}"/>
    </RichTextBox.ContextMenu>
    <dxmvvm:Interaction.Behaviors>
        <dxspch:DXSpellChecker Culture="en-US" CheckAsYouType="True"/>
    </dxmvvm:Interaction.Behaviors>
</RichTextBox>
csharp
void RichTextBox_PreviewMouseRightButtonUp(object sender, MouseButtonEventArgs e)
{
    MenuItems.Clear();
    var commands = this.richTextBox.GetErrorOperationCommands(e.GetPosition(this.richTextBox));
    foreach (var command in commands)
    {
        var menuItem = new MenuItem();
        menuItem.Header = command.Caption;
        menuItem.Click += (s, args) => command.DoCommand();
        menuItem.IsEnabled = command.Enabled;
        MenuItems.Add(menuItem);
    }
    if (MenuItems.Count == 0)
        MenuItems.Add(new MenuItem() { Header = "No Error", IsEnabled = false });
}
vb
Private Sub RichTextBox_PreviewMouseRightButtonUp(ByVal sender As Object, ByVal e As MouseButtonEventArgs)
    MenuItems.Clear()
    Dim commands = Me.richTextBox.GetErrorOperationCommands(e.GetPosition(Me.richTextBox))
    For Each command In commands
        Dim menuItem = New MenuItem()
        menuItem.Header = command.Caption
        AddHandler menuItem.Click, Sub(s, args) command.DoCommand()
        menuItem.IsEnabled = command.Enabled
        MenuItems.Add(menuItem)
    Next command
    If MenuItems.Count = 0 Then
        MenuItems.Add(New MenuItem() With {.Header = "No Error", .IsEnabled = False})
    End If

Inheritance

Object SpellingExtensions

See Also

SpellingExtensions Members

DevExpress.Xpf.SpellChecker Namespace