Search results

Open a dialog on Context Menu item click in Blazor ContextMenu component

28 Jul 2021 / 1 minute to read

This section explains about how to open a dialog on Context Menu item click. This can be achieved by handling dialog open in ItemSelected event of the Context Menu.

In the following sample, Dialog will open while clicking Save As... item.

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

<div id="target">Right click/Touch hold to open the ContextMenu </div>
<SfContextMenu Target="#target" TValue="MenuItem">
        <MenuItem Text="Back"></MenuItem>
        <MenuItem Text="Forward"></MenuItem>
        <MenuItem Text="Reload"></MenuItem>
        <MenuItem Separator="true"></MenuItem>
        <MenuItem Text="Save As..."></MenuItem>
        <MenuItem Text="Print"></MenuItem>
        <MenuItem Text="Cast"></MenuItem>
    <MenuEvents TValue="MenuItem" ItemSelected="@SelectedHandler"></MenuEvents>
<SfDialog @ref="dialogObj" Content="@content" Visible="false" Target="#target" Width="200px" Height="110px">
        <DialogButton Content="Submit" IsPrimary="true" OnClick="@Clicked"></DialogButton>

@code {
    private SfDialog dialogObj;
    private string content = "This file can be saved as PDF";

    private async Task SelectedHandler(MenuEventArgs<MenuItem> e)
        if (e.Item.Text == "Save As...")
            await dialogObj.Show();
    private async Task Clicked(object args)
        await dialogObj.Hide();

    #target {
        border: 1px dashed;
        height: 150px;
        padding: 10px;
        position: relative;
        text-align: justify;
        color: gray;
        user-select: none;

Output be like Context Menu Sample