Skip to main content
All docs
V25.1
  • IContextMenuItemCollection.IndexOf(IContextMenuItem) Method

    Returns the specified item’s position within the item collection.

    Namespace: DevExpress.Blazor.Office

    Assembly: DevExpress.Blazor.v25.1.dll

    NuGet Package: DevExpress.Blazor

    Declaration

    int IndexOf(
        IContextMenuItem menuItem
    )

    Parameters

    Name Type Description
    menuItem IContextMenuItem

    The context menu item.

    Returns

    Type Description
    Int32

    The item’s position in the item collection. -1 if the collection does not contain the specified item.

    Remarks

    The following code snippet adds a custom Show URL item before the Open Hyperlink item if a hyperlink is selected:

    <DxRichEdit CustomizeContextMenu=OnCustomizeContextMenu />
    
    @code {
        DxPopup popup;
        Selection selection;
        string link;
        // ...
        async Task OnCustomizeContextMenu(IContextMenuItemCollection items) {
            var hyperlinks = await selection.ActiveSubDocument.Hyperlinks.GetAllAsync();
            var hyperlink = hyperlinks.SingleOrDefault(h => Enumerable.Range(h.Interval.Start, h.Interval.Length).Contains(selection.CaretPosition));
            link = hyperlink?.Url;
            if (!string.IsNullOrEmpty(link)) {
                var openHyperlinkItem = items[RichEditContextMenuItemNames.OpenHyperlink];
                openHyperlinkItem.BeginGroup = false;
                var index = items.IndexOf(openHyperlinkItem);
                var showURLItem = items.AddCustomItem(index, "Show URL");
                showURLItem.Click = async () => {
                    if (popup is not null)
                        await popup.ShowAsync();
                };
                showURLItem.BeginGroup = true;
            }
        }
    }
    

    Run Demo: Context Menu Customization

    See Also