wpf-17828-controls-and-libraries-spell-checker-examples-implement-check-as-you-type-mode.md
This document contains instructions on how to implement check-as-you-type mode for the standalone SpellChecker component added to text-aware controls (TextEdit and MemoEdit).
Implement a SpellChecker property to access the spell checker component. Set the data context to enable binding.
using System.Windows;
using System.Globalization;
using DevExpress.Xpf.SpellChecker;
namespace WpfApplication1
{
public partial class MainWindow : Window
{
SpellChecker checker;
public MainWindow()
{
DataContext = this;
checker = new SpellChecker();
InitializeComponent();
SpellChecker = checker;
}
public SpellChecker SpellChecker
{
get { return checker; }
private set { checker = value; }
}
}
}
Imports System.Windows
Imports System.Globalization
Imports DevExpress.Xpf.SpellChecker
Namespace WpfApplication1
Partial Public Class MainWindow
Inherits Window
Private checker As SpellChecker
Public Sub New()
DataContext = Me
checker = New SpellChecker()
InitializeComponent()
SpellChecker = checker
End Sub
Public Property SpellChecker() As SpellChecker
Get
Return checker
End Get
Private Set(ByVal value As SpellChecker)
checker = value
End Set
End Property
End Class
End Namespace
In XAML, bind the SpellingSettings.SpellChecker property to the created SpellChecker property. Note that if the SpellingSettings.SpellChecker property is not specified, an internal spell checker is created. The internal spell checker uses SpellingSettings specified in XAML.
xmlns:dxspch="http://schemas.devexpress.com/winfx/2008/xaml/spellchecker"
<dxspch:SpellingSettings.SpellChecker>
<Binding Path="SpellChecker"/>
</dxspch:SpellingSettings.SpellChecker>
Set the SpellChecker.SpellCheckMode property to SpellCheckMode.AsYouType to enable check-as-you-type mode.
using DevExpress.Xpf.Core;
using DevExpress.Xpf.SpellChecker;
using DevExpress.XtraSpellChecker;
using System.Globalization;
public partial class MainWindow : Window
{
SpellChecker checker;
public MainWindow()
{
DataContext = this;
checker = new SpellChecker();
InitializeComponent();
checker.Culture = new CultureInfo("pl-PL");
checker.SpellCheckMode = DevExpress.XtraSpellChecker.SpellCheckMode.AsYouType;
SpellChecker = checker;
}
public SpellChecker SpellChecker
{
get { return checker; }
private set { checker = value; }
}
private void button1_Click(object sender, RoutedEventArgs e)
{
// Start checking the text within a text edit control.
checker.Check(textEdit1);
}
}
Imports System.Windows
Imports System.Globalization
Imports DevExpress.Xpf.SpellChecker
Imports DevExpress.XtraSpellChecker
Namespace WpfApplication1
Partial Public Class MainWindow
Inherits Window
Private checker As SpellChecker
Public Sub New()
DataContext = Me
checker = New SpellChecker()
InitializeComponent()
checker.Culture = New CultureInfo("pl-PL")
checker.SpellCheckMode = SpellCheckMode.AsYouType
SpellChecker = checker
End Sub
Public Property SpellChecker() As SpellChecker
Get
Return checker
End Get
Private Set(ByVal value As SpellChecker)
checker = value
End Set
End Property
Private Sub button1_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
' Start checking the text within a text edit control.
checker.Check(textEdit1)
End Sub
End Class
End Namespace
Specify the following values for the SpellingSettings attributes:
<dxspch:SpellingSettings.SpellChecker>
<Binding Path="SpellChecker"/>
</dxspch:SpellingSettings.SpellChecker>
<dxspch:SpellingSettings.CheckAsYouType>True</dxspch:SpellingSettings.CheckAsYouType>
<dxspch:SpellingSettings.ShowSpellCheckMenu>True</dxspch:SpellingSettings.ShowSpellCheckMenu>
<dxspch:SpellingSettings.UnderlineColor>Blue</dxspch:SpellingSettings.UnderlineColor>
<dxspch:SpellingSettings.UnderlineStyle>WavyLine</dxspch:SpellingSettings.UnderlineStyle>
You can also use the SpellingSettings.DictionarySourceCollection property to add dictionaries to the spell checker. You can add a dictionary as shown in the following code:
<dxspch:SpellingSettings.DictionarySourceCollection>
<dxspch:DictionarySourceCollection>
<dxspch:SpellCheckerOpenOfficeDictionarySource Culture="pl-PL"
DictionaryUri="pack://siteoforigin:,,,/Dictionaries/pl_PL.dic"
GrammarUri="pack://siteoforigin:,,,/Dictionaries/pl_PL.aff"/>
</dxspch:DictionarySourceCollection>
</dxspch:SpellingSettings.DictionarySourceCollection>
When SpellChecker encounters a word not found within dictionaries or a duplicate word, it marks it with a blue wavy line.
Right-click the misspelled word to invoke a menu where you can choose from suggested replacements or select other actions to handle the mistake.