You are viewing help content for pre-release software. This document and the features it describes are subject to change. Switch to the current version.

How to: Access the Rich Text Editor Controls

  • 6 minutes to read

This topic describes how to access and customize the following controls in XAF applications with the Office Module:

Platform

Control

Purpose

WinForms

RichEditControl

Used to show Rich Text documents

ASP.NET Core Blazor

DxRichEdit

Used to show Rich Text documents

ASP.NET Web Forms

ASPxRichEdit

Used to show Rich Text documents

ASP.NET Web Forms

ASPxUploadControl

Used to upload Rich Text documents on a server

Access the WinForms-Specific Control (RichEditControl)

Follow the steps below to access the RichEditControl and enable the Spell Check function.

  1. Create a custom ViewController in the WinForms module project (MySolution.Module.Win).
  2. Add the DevExpress.SpellChecker.v21.2.dll and DevExpress.XtraSpellChecker.v21.2.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.

File: MySolution.Module.Win\Controllers\WinRichEditController.cs(.vb).

using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Office.Win;
using DevExpress.XtraRichEdit;
using DevExpress.XtraSpellChecker;

public partial class WinRichEditController : 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 ASP.NET Web Forms-Specific Controls

Access the ASPxRichEdit Control

Follow the steps below to access the ASPxRichEdit control and enable the Spell Check function.

  1. Create a custom ViewController in the ASP.NET Web Forms module project (MySolution.Module.Web).
  2. Add the DevExpress.Web.ASPxSpellChecker.v21.2.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.

File: MySolution.Module.Web\Controllers\WebRichEditController.cs(.vb).

using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Office.Web;
using DevExpress.Web.ASPxRichEdit;
using DevExpress.Web.ASPxSpellChecker;
using System;
using System.Globalization;
// ...
public class WebRichEditController : 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;
        }
    }
}

Access the ASPxUploadControl

Follow the steps below to access the ASPxUploadControl and set the maximum size of the file to be uploaded to the server.

  1. Create a custom ViewController in the ASP.NET Web Forms module project (MySolution.Module.Web).
  2. In the overridden OnActivated method, handle the ASPxSpreadsheetPropertyEditor.ControlCreated event.
  3. In the event handler, use the MaxFileSize property to specify the maximum size of the file to be uploaded to the server.

File: MySolution.Module.Web\Controllers\WebRichEditUploadController.cs(.vb).

using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Office.Web;
using DevExpress.Web;
using System;
// ...
public class WebRichEditUploadController : ViewController<DetailView> {
    protected override void OnActivated() {
        base.OnActivated();
        foreach (ASPxRichTextPropertyEditor editor in View.GetItems<ASPxRichTextPropertyEditor>()) {
            if (editor.ASPxUploadControl != null) {
                CustomizeRichEditUploadControl(editor.ASPxUploadControl);
            }
            else {
                editor.ControlCreated += Editor_ControlCreated;
            }
        }
    }
    private void Editor_ControlCreated(object sender, EventArgs e) {
        ASPxUploadControl richEditUploadControl = ((ASPxRichTextPropertyEditor)sender).ASPxUploadControl;
        CustomizeRichEditUploadControl(richEditUploadControl);
    }
    private void CustomizeRichEditUploadControl(ASPxUploadControl uploadControl) {
        uploadControl.ValidationSettings.MaxFileSize = 104857600;
    }
    protected override void OnDeactivated() {
        base.OnDeactivated();
        foreach (ASPxRichTextPropertyEditor editor in View.GetItems<ASPxRichTextPropertyEditor>()) {
            editor.ControlCreated -= Editor_ControlCreated;
        }
    }
}

Access the ASP.NET Core Blazor-Specific Control’s Component Model (DxRichEditModel)

Follow these steps to access the DxRichEditModel component model. A component model is the representation of a Blazor component in code. When you modify the model, the underlying component reflects these changes. Refer to the following help topic for more information on component models: How to: Implement a Property Editor Based on a Custom Component (Blazor).

  1. Create a custom Controller in the ASP.NET Core Blazor module project (MySolution.Module.Blazor).
  2. Override the OnActivated method and handle the RichTextPropertyEditor.ControlCreated event.
  3. In the event handler, access the DevExpress.ExpressApp.Office.Blazor.Components.Models.DxRichEditModel component model and specify its ViewType property to change a document view layout type (see ViewType).

File: MySolution.Module.Blazor\Controllers\BlazorRichEditController.cs.

using System;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Office.Blazor.Components.Models;
using DevExpress.ExpressApp.Office.Blazor.Editors;
using DevExpress.ExpressApp.Office.Blazor.Editors.Adapters;
//...
public class BlazorRichEditController : ViewController<DetailView> {
    protected override void OnActivated() {
        base.OnActivated();
        foreach(RichTextPropertyEditor editor in View.GetItems<RichTextPropertyEditor>()) {
            if(editor.Control != null) {
                CustomizeRichEditComponentModel(((RichTextEditorComponentAdapter)editor.Control).ComponentModel);
            }
            else {
                editor.ControlCreated += Editor_ControlCreated;
            }
        }
    }
    private void Editor_ControlCreated(object sender, EventArgs e) {
        CustomizeRichEditComponentModel(((RichTextEditorComponentAdapter)((RichTextPropertyEditor)sender).Control).ComponentModel);
    }
    private void CustomizeRichEditComponentModel(DxRichEditModel richEditModel) {
        richEditModel.ViewType = DevExpress.Blazor.RichEdit.ViewType.Simple;
    }
    protected override void OnDeactivated() {
        base.OnDeactivated();
        foreach(RichTextPropertyEditor editor in View.GetItems<RichTextPropertyEditor>()) {
            editor.ControlCreated -= Editor_ControlCreated;
        }
    }
}
See Also