Back to Devexpress

RichEditControl.HoverMenuShowing Event

wpf-devexpress-dot-xpf-dot-richedit-dot-richeditcontrol-8a4c8032.md

latest5.4 KB
Original Source

RichEditControl.HoverMenuShowing Event

Fires before the hover menu of the control is displayed.

Namespace : DevExpress.Xpf.RichEdit

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

NuGet Package : DevExpress.Wpf.RichEdit

Declaration

csharp
public event HoverMenuShowingEventHandler HoverMenuShowing
vb
Public Event HoverMenuShowing As HoverMenuShowingEventHandler

Event Data

The HoverMenuShowing event's data class is HoverMenuShowingEventArgs. The following properties provide information specific to this event:

PropertyDescription
MenuGets or sets the hover menu displayed in the RichEditControl.

Remarks

Handle the HoverMenuShowing event to modify the default hover menu of the RichEditControl.

Note

The Hover menu is available only when the RichEditControl provides a Bar or Ribbon UI. Otherwise, the HoverMenuShowing event does not occur. To learn how to implement a Bar/Ribbon interface, refer to the Create a Simple Rich Text Editor and Create Separate Command UI for a Rich Text Editor documents.

This code snippet demonstrates how to handle the RichEditControl.HoverMenuShowing event to add and remove menu items. Menu buttons representing the IncrementIndentCommand and the DecrementIndentCommand commands are removed. A new custom command MySmileyCommand , which implements the ICommand interface, is added to the menu.

csharp
using System.Windows;
using DevExpress.Xpf.Bars;
using DevExpress.Xpf.RichEdit;
using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.Commands;
using DevExpress.XtraRichEdit.Menu;
using DevExpress.Xpf.RichEdit.Menu;
        void richEditControl1_HoverMenuShowing(object sender, HoverMenuShowingEventArgs e)
        {
            // Remove DecreaseIndent and IncreaseIndent command menu items.
            for (int i = 0; i < e.Menu.ItemsCount; i++) {
                BarItemLink bLink = (BarItemLink)e.Menu.ItemLinks[i];
                RichEditUICommand cmd = (RichEditUICommand)bLink.Item.Command;
                if (cmd.CommandId == RichEditCommandId.DecreaseIndent 
|| cmd.CommandId == RichEditCommandId.IncreaseIndent)
                    e.Menu.ItemLinks.Remove(bLink); 
            }
            // Add a separator.
            BarItemLinkSeparator itemSep = new BarItemLinkSeparator();
            e.Menu.ItemLinks.Add(itemSep);
            // Create a new menu item and add it to the hover menu.
            RichEditMenuItem item1 = new RichEditMenuItem();
            item1.Content = "Replace Emoticon with Smiley";
            MySmileyCommand cmd_toAdd = new MySmileyCommand(richEditControl1);
            item1.Command = cmd_toAdd;
            item1.Glyph = cmd_toAdd.Glyph;
            e.Menu.ItemLinks.Add(item1);
        }
vb
Imports System.Windows
Imports DevExpress.Xpf.Bars
Imports DevExpress.Xpf.RichEdit
Imports DevExpress.XtraRichEdit
Imports DevExpress.XtraRichEdit.Commands
Imports DevExpress.XtraRichEdit.Menu
Imports DevExpress.Xpf.RichEdit.Menu
        Private Sub richEditControl1_HoverMenuShowing(ByVal sender As Object, ByVal e As HoverMenuShowingEventArgs)
            ' Remove DecreaseIndent and IncreaseIndent command menu items.
            For i As Integer = 0 To e.Menu.ItemsCount - 1
                Dim bLink As BarItemLink = CType(e.Menu.ItemLinks(i), BarItemLink)
                Dim cmd As RichEditUICommand = CType(bLink.Item.Command, RichEditUICommand)
                If cmd.CommandId = RichEditCommandId.DecreaseIndent OrElse cmd.CommandId = RichEditCommandId.IncreaseIndent Then
                    e.Menu.ItemLinks.Remove(bLink)
                End If
            Next i
            ' Add a separator.
            Dim itemSep As New BarItemLinkSeparator()
            e.Menu.ItemLinks.Add(itemSep)
            ' Create a new menu item and add it to the hover menu.
            Dim item1 As New RichEditMenuItem()
            item1.Content = "Replace Emoticon with Smiley"
            Dim cmd_toAdd As New MySmileyCommand(richEditControl1)
            item1.Command = cmd_toAdd
            item1.Glyph = cmd_toAdd.Glyph
            e.Menu.ItemLinks.Add(item1)
        End Sub

See Also

RichEditHoverMenu

RichEditControl Class

RichEditControl Members

DevExpress.Xpf.RichEdit Namespace