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

Use Rich Text Documents in Business Objects

  • 3 minutes to read

This topic describes how to customize the behavior of the RichTextPropertyEditor and ASPxRichTextPropertyEditor (Beta) and use these editors for byte array and string properties in WinForms and ASP.NET applications. The following images demonstrate these Property Editors assigned to the Document.Text property:

Document Storage Formats

When you use the RichTextPropertyEditor or ASPxRichTextPropertyEditor for a byte array property, your application saves the documents in the DOCX format. The RTF format is used for the string properties (you can optionally change the format to HTML). We recommend using byte arrays instead of strings to store your documents because the DOCX format works faster with large documents and supports more formatting options.

Enable the RichTextPropertyEditor or ASPxRichTextPropertyEditor in Code

To enable the RichTextPropertyEditor or ASPxRichTextPropertyEditor for a business class’ property, apply the EditorAliasAttribute to this property as follows:

using DevExpress.ExpressApp.Editors;
using DevExpress.Persistent.Base;
using DevExpress.Persistent.BaseImpl;
// ...
// Byte array property example:
private byte[] text;
[Size(SizeAttribute.Unlimited)]
[EditorAlias(EditorAliases.RichTextPropertyEditor)] 
public byte[] Text { 
    get { return text; }
    set { SetPropertyValue(nameof(Text), ref text, value); }
}

// String property example:
private string text;
[Size(SizeAttribute.Unlimited)]
[EditorAlias(EditorAliases.RichTextPropertyEditor)] 
public string Text { 
    get { return text; }
    set { SetPropertyValue(nameof(Text), ref text, value); }
}

Enable the RichTextPropertyEditor or ASPxRichTextPropertyEditor in the Model Editor

Navigate to the required Views | <DetailView> | Items | <PropertyEditor> node and set the PropertyEditorType property to DevExpress.ExpressApp.Office.Win.RichTextPropertyEditor or DevExpress.ExpressApp.Office.Web.ASPxRichTextPropertyEditor.

Customize the Behavior of the RichTextPropertyEditor or ASPxRichTextPropertyEditor

You can use the Model Editor in a WinForms or ASP.NET application project to perform the customizations described below.

Use MenuManagerType in a Specific Detail View

The RichEditPropertyEditor is created with the menu manager containing the Ribbon Control or Bars. The ASPxRichEditPropertyEditor is created with the menu manager containing only the Ribbon Control.

You can specify the editor’s MenuManagerType (WinForms / ASP.NET) in the Views | <DetailView> | Items | <PropertyEditor> node.

Change the Document Storage Format

For string properties, you can choose the document storage format (RTF or HTML) using the BOModel | <Class> | OwnMembers | <Member> node’s DocumentStorageFormat property.

The format is always DOCX for byte array properties.

Specify the Column Height in a List View in a WinForms application

Use the Views | <ListView> | Columns | <Column> node’s CustomHeight property to change the editor’s height if you are using the RichEditPropertyEditor in a ListView Column.

Edit the Document in a Separate Window

In WinForms applications, you can open the document in a new modal window using the Show in popup context menu command.

In ASP.NET applications, you can edit the document in full-screen mode.

Customize the Menu

The RichEditPropertyEditor‘s menu does not display all the available toolbars and ribbon tabs by default. You can use the static RichEditPropertyEditor.DefaultRichEditToolbarType property to customize the toolbars. The available toolbars are listed in the RichEditToolbarType enumeration.

using DevExpress.XtraRichEdit;
using DevExpress.ExpressApp.Office.Win;
// ...
RichTextPropertyEditor.DefaultRichEditToolbarType = 
    RichEditToolbarType.Home | RichEditToolbarType.Insert | RichEditToolbarType.File | 
    RichEditToolbarType.FloatingObject | RichEditToolbarType.Table | RichEditToolbarType.HeaderFooter;

Handle the MenuManagerController.CustomizeRichEditToolbarType event to change the toolbars for a specific editor only.

You can customize the Bars menu at runtime. The result is saved to the user’s model differences.