Skip to main content
A newer version of this page is available. .

Access the Rich Text Editor Controls

  • 3 minutes to read

This topic describes how to access and customize the RichEditControl and ASPxRichEdit objects in XAF applications with the Office Module. The steps below demonstrate how to enable the Spell Check function (WinForms/ASP.NET). A similar approach may be used for other customizations.

Access the WinForms-Specific Control (RichEditControl)

  1. Create a custom ViewController in the WinForms module project.
  2. Add the DevExpress.SpellChecker.v19.1.dll and DevExpress.XtraSpellChecker.v19.1.dll assemblies to the project references.
  3. Override the OnActivated method and handle the RichTextServiceController.CustomizeRichEditControl event. In the event handler, create and setup the SpellChecker object and pass this object to the SpellChecker property.

    using DevExpress.ExpressApp;
    using DevExpress.ExpressApp.Office.Win;
    using DevExpress.XtraRichEdit;
    using DevExpress.XtraSpellChecker;
    
    public partial class CustomRichTextController : ViewController {
    // ...
        protected override void OnActivated() {
            base.OnActivated();
            RichTextServiceController controller = Frame.GetController<RichTextServiceController>();
            if(controller != null) {
                controller.CustomizeRichEditControl += Controller_CustomizeRichEditControl;
            }
        }
        private void Controller_CustomizeRichEditControl(object sender, CustomizeRichEditEventArgs e) {
            SpellChecker spellChecker = new SpellChecker();
            spellChecker.SetSpellCheckerOptions(e.RichEditControl, new OptionsSpelling());
            spellChecker.SpellCheckMode = SpellCheckMode.AsYouType;
            e.RichEditControl.SpellChecker = spellChecker;
        }
    }
    

Note

The English dictionary is the default for the Spell Checker. Refer to the Dictionaries topic to see how to change the dictionary.

Access the ASP.NET-Specific Control (ASPxRichEdit)

  1. Create a custom ViewController in the ASP.NET module project.
  2. Add the DevExpress.Web.ASPxSpellChecker.v19.1.dll assembly to the project references.
  3. Override the OnActivated method and handle the ASPxRichTextPropertyEditor.ControlCreated event. In the event handler, create and setup the ASPxSpellCheckerOpenOfficeDictionary object and add this object to the Dictionaries collection. Set the Enabled property to true to enable the Spell Checker component.

    using DevExpress.ExpressApp;
    using DevExpress.ExpressApp.Office.Web;
    using DevExpress.Web.ASPxRichEdit;
    using DevExpress.Web.ASPxSpellChecker;
    using System;
    using System.Globalization;
    // ...
    public class RichEditViewController : ViewController<DetailView> {
        protected override void OnActivated() {
            base.OnActivated();
            foreach(ASPxRichTextPropertyEditor editor in View.GetItems<ASPxRichTextPropertyEditor>()) {
                if(editor.ASPxRichEditControl != null) {
                    CustomizeRichEditControl(editor.ASPxRichEditControl);
                } else {
                    editor.ControlCreated += Editor_ControlCreated;
                }
            }
        }
        private void Editor_ControlCreated(object sender, EventArgs e) {
            ASPxRichEdit richEdit = ((ASPxRichTextPropertyEditor)sender).ASPxRichEditControl;
            CustomizeRichEditControl(richEdit);
        }
        private void CustomizeRichEditControl(ASPxRichEdit richEdit) {
            ASPxSpellCheckerOpenOfficeDictionary dictionary = new ASPxSpellCheckerOpenOfficeDictionary();
            dictionary.GrammarPath = "~/App_Data/Dictionaries/en_US.aff";
            dictionary.DictionaryPath = "~/App_Data/Dictionaries/en_US.dic";
            dictionary.Culture = new CultureInfo("en-US");
            dictionary.CacheKey = "enDic";
            richEdit.Settings.SpellChecker.Dictionaries.Add(dictionary);
            richEdit.Settings.SpellChecker.Enabled = true;
            richEdit.Settings.SpellChecker.SuggestionCount = 4;
        }
        protected override void OnDeactivated() {
            base.OnDeactivated();
            foreach(ASPxRichTextPropertyEditor editor in View.GetItems<ASPxRichTextPropertyEditor>()) {
                editor.ControlCreated -= Editor_ControlCreated;
            }
        }
    }