Back to Devexpress

DxContextMenu.ShowAsync(Double, Double, ContextMenuPosition) Method

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

latest3.0 KB
Original Source

DxContextMenu.ShowAsync(Double, Double, ContextMenuPosition) Method

Displays the Context Menu with custom horizontal and vertical offsets from 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(
    double x,
    double y,
    ContextMenuPosition position
)

Parameters

NameTypeDescription
xDouble

Specifies the horizontal offset (in pixels) from the base Context Menu position.

| | y | Double |

Specifies the vertical offset (in pixels) from the base Context Menu position.

| | position | ContextMenuPosition |

An enumeration value.

|

Returns

TypeDescription
Task

The task completed when the context menu is displayed.

|

Remarks

Call this method to show the context menu next to the target UI element with the (x,y) shift. Use the PositionTarget property to specify this element.

The following example displays the context menu at the right edge of the <div> element and additionally shifts the menu down by 25 pixels:

razor
<DxButton Text="Show Context Menu" Click="() => ContextMenu.ShowAsync(0, 25, ContextMenuPosition.Right)" />

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

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

@code {
    DxContextMenu ContextMenu { get; set; }
}
css
.context-menu {
  margin-top: 15px;
  height: 50px;
  width: 200px;
  border: 1px solid black;
}
.fw-600 {
    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