Back to Devexpress

DxContextMenu.ShowAsync(ContextMenuPosition) Method

blazor-devexpress-dot-blazor-dot-dxcontextmenu-dot-showasync-x28-devexpress-dot-blazor-dot-contextmenuposition-x29.md

latest2.6 KB
Original Source

DxContextMenu.ShowAsync(ContextMenuPosition) Method

Displays the Context Menu at one of the base positions in relation to the target UI element.

Namespace : DevExpress.Blazor

Assembly : DevExpress.Blazor.v25.2.dll

NuGet Package : DevExpress.Blazor

Declaration

csharp
public Task ShowAsync(
    ContextMenuPosition position
)

Parameters

NameTypeDescription
positionContextMenuPosition

An enumeration value.

|

Returns

TypeDescription
Task

The task completed when the context menu is displayed.

|

Remarks

Call this method to show the context menu in relation to the target element. Use the PositionTarget property to specify this element. If you do not specify the PositionTarget property value, this method displays the context menu at the top left corner of a web page.

The following example displays the context menu at the top of the <div> element:

razor
<DxButton Text="Show Context Menu" 
          Click="() => ContextMenu.ShowAsync(ContextMenuPosition.Top)" />

<div class="context-menu-container"
     @oncontextmenu:preventDefault>
    <span class="fw">RIGHT-CLICK TO SHOW THE CONTEXT MENU</span>
</div>

<DxContextMenu @ref="ContextMenu"
               PositionTarget=".context-menu-container">
    <Items>
        <DxContextMenuItem Text="Open" />
        <DxContextMenuItem Text="Copy" />
        <DxContextMenuItem Text="Delete" />
    </Items>
</DxContextMenu>

@code {
    DxContextMenu ContextMenu { get; set; }
}
css
.context-menu-container {
    margin-top: 100px;
    height: 50px;
    width: 200px;
    border: 1px solid black;
}
.fw {
    font-weight: 600;
}

To execute custom code when the context menu is displayed, handle the Shown event. Call the HideAsync() method to hide the context menu.

Run Demo: Context Menu

See Also

DxContextMenu Class

DxContextMenu Members

DevExpress.Blazor Namespace