Skip to main content
All docs
V25.1
  • ISpellCheckService.AddToDictionary(String) Method

    Adds the selected word to a dictionary after a user clicks the Add to dictionary command in the context menu.

    Namespace: DevExpress.Blazor.RichEdit

    Assembly: DevExpress.Blazor.v25.1.dll

    NuGet Package: DevExpress.Blazor

    Declaration

    void AddToDictionary(
        string word
    )

    Parameters

    Name Type Description
    word String

    The selected word.

    Remarks

    Set the AddToDictionaryEnabled property to true to display the Add to dictionary command in the context menu. After a user clicks this command, the component passes the selected word to the AddToDictionary method. Implement this method to save the word to your dictionary storage.

    The following code snippet implements an ISpellCheckService interface:

    using DevExpress.Blazor.RichEdit;
    using System.Collections.Generic;
    using System.Globalization;
    using System.IO;
    using System.Linq;
    
    public class MySpellCheckService : ISpellCheckService {
        public CultureInfo Culture { get; set; }
        public bool AddToDictionaryEnabled { get; }
        public int MaxSuggestionCount { get; }
        string PathToDictionary { get;}
        List<string> CorrectWords { get;}
    
        public MySpellCheckService(string path) {
            PathToDictionary = path;
            Culture = CultureInfo.InvariantCulture;
            AddToDictionaryEnabled = true;
            MaxSuggestionCount = 7;
            CorrectWords = File.ReadLines(PathToDictionary).ToList();
            CorrectWords.Sort();
        }
    
        public void AddToDictionary(string word) {
            if (Culture.TwoLetterISOLanguageName == "en") {
                word = word.ToLower();
                int placeToInsert = CorrectWords.BinarySearch(word);
                CorrectWords.Insert(placeToInsert, word);
                File.AppendAllText(PathToDictionary, word + '\n');
            }
        }
    
        public bool CheckWordSpelling(string word) {
            if (Culture.TwoLetterISOLanguageName == "en") {
                int index = CorrectWords.BinarySearch(word.ToLower());
                return (index >= 0);
            }
            return false;
        } 
    
        public string[] GetSpellingSuggestions(string word) {
            List<string> suggestions = new List<string>();
            // Generate suggestions and add them to the list
            return suggestions.ToArray();
        }
    }
    

    Refer to the following topic for more information about the built-in spell check service: Spell Check.

    See Also