Skip to main content

PopupMenuShowingEventArgs.Customizations Property

Provides access to the collection of context menu customization actions.

Namespace: DevExpress.Xpf.RichEdit

Assembly: DevExpress.Xpf.RichEdit.v23.2.dll

NuGet Package: DevExpress.Wpf.RichEdit

Declaration

public BarManagerActionCollection Customizations { get; }

Property Value

Type Description
BarManagerActionCollection

A collection of bar actions used to customize the context menu.

Remarks

The Customizations property allows you to customize the Rich Text Editor’s context menus. You can add or remove menu items. The PopupMenuShowingEventArgs.MenuType property allows you to determine for which element (document text, a header or footer, a picture, etc.) the menu is invoked.

The example below customizes the Text context menu as follows:

  • Creates new Highlight Selection and Insert Picture items
  • Removes the Increase Indent and Decrease Indent items

Custom context menu for the Rich Text Editor

<dxre:RichEditControl Name="richTextEditor" 
                      PopupMenuShowing="richTextEditor_PopupMenuShowing">
using DevExpress.XtraRichEdit.API.Native;
using DevExpress.Xpf.RichEdit;
using DevExpress.Xpf.Bars;
using DevExpress.Xpf.RichEdit.Menu;
using DevExpress.XtraRichEdit.Commands;
// ...

private void richTextEditor_PopupMenuShowing(object sender, PopupMenuShowingEventArgs e) {
    // Check whether the event is raised for document text.
    if (e.MenuType == RichEditMenuType.Text) {
        // Create a menu item to insert a picture
        // and bind this item to the Rich Text Editor's command.
        e.Customizations.Add(new BarButtonItem() {
            Command = RichEditUICommand.InsertFloatingPicture,
            Content = "Insert Picture",
            CommandParameter = richTextEditor
        });

        // Create a custom menu item to highlight selected text.
        var menuItem = new BarButtonItem() {
            Name = "highlightSelectionItem",
            Content = "Highlight Selection"
        };
        menuItem.ItemClick += MenuItem_ItemClick; ;
        e.Customizations.Add(menuItem);
    }

    // Remove the "Increase Indent" item from the menu.
    e.Customizations.Add(new RemoveRichEditCommandAction() {
        Id = RichEditCommandId.IncreaseIndent
    });

    // Remove the "Decrease Indent" item from the menu.
    e.Customizations.Add(new RemoveRichEditCommandAction() {
        Id = RichEditCommandId.DecreaseIndent
    });
}

private void MenuItem_ItemClick(object sender, ItemClickEventArgs e) {
    var selectedRanges = richTextEditor.Document.Selections;
    foreach (var range in selectedRanges) {
        var charProps = richTextEditor.Document.BeginUpdateCharacters(range);
        charProps.BackColor = System.Drawing.Color.Yellow;
        richTextEditor.Document.EndUpdateCharacters(charProps);
    }
}
See Also