Back to Devexpress

SpellCheckExtensions.AddSpellCheck(IDevExpressBlazorBuilder, Action<SpellCheckOptions>) Method

blazor-devexpress-dot-blazor-dot-richedit-dot-spellcheck-dot-spellcheckextensions-dot-addspellcheck-x28-idevexpressblazorbuilder-action-spellcheckoptions-x29.md

latest5.0 KB
Original Source

SpellCheckExtensions.AddSpellCheck(IDevExpressBlazorBuilder, Action<SpellCheckOptions>) Method

Adds the built-in spell check service to the application’s service collection and configures the service options.

Namespace : DevExpress.Blazor.RichEdit.SpellCheck

Assembly : DevExpress.Blazor.RichEdit.v25.2.dll

NuGet Package : DevExpress.Blazor.RichEdit

Declaration

csharp
public static IDevExpressBlazorBuilder AddSpellCheck(
    this IDevExpressBlazorBuilder builder,
    Action<SpellCheckOptions> configure
)

Parameters

NameTypeDescription
builderIDevExpressBlazorBuilder

An object that can be used to configure internal DevExpress Blazor services.

|

Optional Parameters

NameTypeDefaultDescription
configureAction<SpellCheckOptions>null

A delegate method that configures the service options.

|

Returns

TypeDescription
IDevExpressBlazorBuilder

An object that can be used to further configure internal DevExpress Blazor services.

|

Remarks

Call the AddSpellCheck method to register the built-in spell check service in your application and configure the following spell check options:

AddToDictionaryActionAllows you to implement a delegate method that writes the selected word to a dictionary file. The Rich Text Editor executes this method after a user clicks the Add to dictionary command in the context menu. If you do not set the AddToDictionaryAction property value, the component hides the command.DictionariesStores a list of dictionaries you added. To extend the dictionary list, pass a simple, ISpell, or Hunspell dictionary to the list’s Add method.FileProviderSpecifies a file provider that accesses dictionary files. The FileNotFoundException error occurs if you do not set a file provider, but add a dictionary.MaxSuggestionCountSpecifies the maximum number of suggestions that the Rich Text Editor should display in its context menu. The component can display up to 15 suggestions.

The following code snippet registers the built-in spell check service:

csharp
var DictionaryFiles = new Dictionary<string, string>() {
    { "de-DE", "de//de.dic" },
    { "fr-FR", "fr//fr.dic" },
};
var builder = WebApplication.CreateBuilder(args);
// ...
builder.Services.AddDevExpressBlazor().AddSpellCheck(opts => {
    opts.FileProvider = new PhysicalFileProvider(
        Path.Combine(Directory.GetCurrentDirectory(), "Data", "Dictionaries"));
    opts.Dictionaries.Add(new Dictionary {
        DictionaryPath = "de\\de.dic",
        AlphabetPath = "de\\alphabet.txt",
        Culture = "de-DE"
    });
    opts.Dictionaries.Add(new Dictionary {
        DictionaryPath = "fr\\fr.dic",
        AlphabetPath = "fr\\alphabet.txt",
        Culture = "fr-FR"
    });
    opts.AddToDictionaryAction = (word, culture) => {
        string dictionaryFile = DictionaryFiles.GetValueOrDefault(culture.Name);
        if (dictionaryFile != default) {
            var filePath = opts.FileProvider.GetFileInfo(dictionaryFile).PhysicalPath;
            File.AppendAllText(filePath, "\n" + word);
        }
    };
    opts.MaxSuggestionCount = 7;
});

View Example: How to Customize the Built-in Spell Check Services

Refer to the following topic for additional information: Spell Check.

See Also

SpellCheckExtensions Class

SpellCheckExtensions Members

DevExpress.Blazor.RichEdit.SpellCheck Namespace