Click here to Skip to main content
Click here to Skip to main content

Tagged as

AvalonEdit and Spell check

, 14 Mar 2013
Rate this:
Please Sign up or sign in to vote.
Quick hack for spell check with AvalonEdit.

Introduction  

As the name of the article implies, this is a quick hack to add spell check in your application using the brilliant AvalonEdit. This is a quick tricky/dirty way to implement spell check using the built-in spell checker in .NET without relying on 3rd party libraries. Note that this might not be the most efficient way of spell check. 

Background  

AvalonEdit is a popular open source text editor control used in #D and widely used by many open source developers in their open source projects. When I started using AvalonEdit, I wanted to add spell check in my application. Initially, I was under the assumption that AvalonEdit inherits from TextBoxBase which means that I can just use the inbuilt spell checker. However that is not the case - AvalonEdit inherits from Control.

The Idea 

In my implementation (See source code) - there are two pieces of development: 

  1. Every AvalonEdit text editor control has a corresponding TextBox control exclusively to get spelling errors. Every change to the text editor will also update the text box - thereby letting the application get the spelling errors. This has been implemented by creating a behavior called SpellCheckBehavior for AvalonEdit.
  2. A new DocumentColorizingTransformer called the SpellingErrorColorizer, is available as a part of the code. This needs to be added to the list of line transformers in the text view of your editor. The idea behind this transformer is using a static text box which can give the errors on the DocumentLine that needs to be processed. 

The Result

Using the code

Download the code and have a look at it as it is self explanatory. 

In MainWindow.xaml, create an instance of the text editor and add the behavior. 

<avalonedit:TextEditor Name="textEditor" FontSize="20">
    <i:Interaction.Behaviors>
        <SpellCheckAvalonEdit:SpellCheckBehavior />
    </i:Interaction.Behaviors>
</avalonedit:TextEditor>  

In MainWindow.xaml.cs, add the SpellingErrorColorizer to the line transformers.

public MainWindow()
{
    InitializeComponent();
    textEditor.TextArea.TextView.LineTransformers.Add(new SpellingErrorColorizer());
} 

Note: In this implementation, I did not care about the performance. If you have a better suggestions, please share/contribute. 

History 

  • 03/11/13 - First spell check idea.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)

Share

About the Author

Chandramouleswaran
Software Developer
United States United States
Hello! I'm a 26 year old, WPF/C# self-learned software developer, musician from India with a Master's degree in Computer science. I believe that every piece of software and information/knowledge is available for free for those who seek it.
 
My projects are available in my Webpage hosted on Github. I am eager to learn new things everyday, explore new technologies and solve problems.
Follow on   Twitter   Google+

Comments and Discussions

 
QuestionIs MSWord on machine is needed where this application will run? PinmemberHM India1-Aug-13 12:36 
AnswerRe: Is MSWord on machine is needed where this application will run? PinmemberChandramouleswaran1-Aug-13 15:50 
QuestionDownload unavailable PinmemberDirkster9914-Mar-13 2:09 
AnswerRe: Download unavailable PinmemberChandramouleswaran14-Mar-13 4:48 
GeneralRe: Download unavailable PinmemberDirkster9915-Mar-13 10:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web02 | 2.8.140827.1 | Last Updated 14 Mar 2013
Article Copyright 2013 by Chandramouleswaran
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid