Table of Contents

Property CheckSpelling

Namespace
Alternet.Editor.Wpf
Assembly
Alternet.Editor.Wpf.v9.dll

CheckSpelling

Gets or sets a value indicating whether the document can check spelling for its content.

public virtual bool CheckSpelling { get; set; }

Property Value

bool

Examples

Here is how to use a CheckSpelling in the C# code:

using System.Windows;
using Alternet.Editor.Wpf;
using Alternet.Syntax.Lexer;

public partial class MainWindow : Window
{
    private TextSource textSource;
    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
        var textEdit1 = new TextEditor();
        textSource = new TextSource();
        textSource.LoadFile("myfile.txt");
        textEdit1.Source = this.textSource;
        textSource.CheckSpelling = true;
        textEdit1.Spelling.WordSpell += new WordSpellEvent(WordSpell);
    }

    private void WordSpell(object sender, WordSpellEventArgs e)
    {
        ITextSource source = (ITextSource)sender;
        bool correct = (wordList != null) ? wordList.Check(e.Text) : true;
        if (source.Lexer != null)
        {
            LexToken tok = (LexToken)(e.ColorStyle.Data - 1);
            if ((tok == LexToken.String) || (tok == LexToken.Comment) || (tok == LexToken.XmlComment))
                e.Correct = (e.Text.Length <= 1) || correct;
        }
        else
            e.Correct = (e.Text.Length <= 1) || correct;
    }
}

Here is how to use a CheckSpelling in the Visual Basic code:

Imports System.Windows
Imports Alternet.Editor.Wpf
Imports Alternet.Syntax.Lexer

Partial Public Class MainWindow
    Inherits Window

    Private textSource As TextSource

    Private Sub Window_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
        Dim textEdit1 = New TextEditor()
        textSource = New TextSource()
        textSource.LoadFile("myfile.txt")
        textEdit1.Source = Me.textSource
        textSource.CheckSpelling = True
        AddHandler textEdit1.Spelling.WordSpell, AddressOf WordSpell
    End Sub

    Private Sub WordSpell(ByVal sender As Object, ByVal e As WordSpellEventArgs)
        Dim source As ITextSource = CType(sender, ITextSource)
        Dim correct As Boolean = If((wordList IsNot Nothing), wordList.Check(e.Text), True)

        If source.Lexer IsNot Nothing Then
            Dim tok As LexToken = CType((e.ColorStyle.Data - 1), LexToken)
            If (tok = LexToken.String) OrElse (tok = LexToken.Comment) OrElse (tok = LexToken.XmlComment) Then e.Correct = (e.Text.Length <= 1) OrElse correct
        Else
            e.Correct = (e.Text.Length <= 1) OrElse correct
        End If
    End Sub
End Class

Remarks

Set CheckSpelling property to true to enable the spelling checking of the text.

To provide real-world spelling, you will need to implement check spelling logic using third-party dictionaries.