Search results

Open and close Context Menu in Blazor ContextMenu component

28 Jul 2021 / 1 minute to read

Open and close the Context Menu manually whenever required by using the Open and Close methods. In the following sample, the Context Menu manually open while clicking the button using Open method with ClientX and ClientY coordinates. To manually close the Context Menu, Close method can be used.

Copied to clipboard
@using Syncfusion.Blazor.Navigations
@using Syncfusion.Blazor.Buttons

<div id="target">
    <SfContextMenu @ref="contextMenuObj" TValue="MenuItem">
            <MenuItem Text="Cut"></MenuItem>
            <MenuItem Text="Copy"></MenuItem>
            <MenuItem Text="Paste"></MenuItem>
    <SfButton @onclick="OpenContextMenu">Open ContextMenu</SfButton>

@code {
    SfContextMenu<MenuItem> contextMenuObj;
    private void OpenContextMenu(MouseEventArgs e)
        contextMenuObj.Open(e.ClientX, e.ClientY);

Output be like

Context Menu Sample