Class ContextMenuService
Class ContextMenuService. Contains various methods with options to open and close context menus.
Should be added as scoped service in the application services and RadzenContextMenu should be added in application main layout.
Implements the
Inheritance
Namespace: Radzen
Assembly: Radzen.Blazor.dll
Syntax
public class ContextMenuService : IDisposable
Examples
@inject ContextMenuService ContextMenuService
<RadzenButton Text="Show context menu" ContextMenu=@(args => ShowContextMenuWithContent(args)) />
@code {
void ShowContextMenuWithContent(MouseEventArgs args) => ContextMenuService.Open(args, ds =>
@<RadzenMenu Click="OnMenuItemClick">
<RadzenMenuItem Text="Item1" Value="1"></RadzenMenuItem>
<RadzenMenuItem Text="Item2" Value="2"></RadzenMenuItem>
<RadzenMenuItem Text="More items" Value="3">
<RadzenMenuItem Text="More sub items" Value="4">
<RadzenMenuItem Text="Item1" Value="5"></RadzenMenuItem>
<RadzenMenuItem Text="Item2" Value="6"></RadzenMenuItem>
</RadzenMenuItem>
</RadzenMenuItem>
</RadzenMenu>);
void OnMenuItemClick(MenuItemEventArgs args)
{
Console.WriteLine($"Menu item with Value={args.Value} clicked");
}
}
Constructors
ContextMenuService(NavigationManager)
Initializes a new instance of the ContextMenuService class.
Declaration
public ContextMenuService(NavigationManager uriHelper)
Parameters
Type | Name | Description |
---|---|---|
NavigationManager | uriHelper | The URI helper. |
Methods
Close()
Closes this instance.
Declaration
public void Close()
Dispose()
Disposes this instance.
Declaration
public void Dispose()
Open(MouseEventArgs, IEnumerable<ContextMenuItem>, Action<MenuItemEventArgs>)
Opens the specified arguments.
Declaration
public void Open(MouseEventArgs args, IEnumerable<ContextMenuItem> items, Action<MenuItemEventArgs> click = null)
Parameters
Type | Name | Description |
---|---|---|
MouseEventArgs | args | The |
IEnumerable<ContextMenuItem> | items | The items. |
Action<MenuItemEventArgs> | click | The click. |
Open(MouseEventArgs, RenderFragment<ContextMenuService>)
Opens the specified arguments.
Declaration
public void Open(MouseEventArgs args, RenderFragment<ContextMenuService> childContent)
Parameters
Type | Name | Description |
---|---|---|
MouseEventArgs | args | The |
RenderFragment<ContextMenuService> | childContent | Content of the child. |
Events
OnClose
Raises the Close event.
Declaration
public event Action OnClose
Event Type
Type | Description |
---|---|
Action |
OnNavigate
Occurs when [on navigate].
Declaration
public event Action OnNavigate
Event Type
Type | Description |
---|---|
Action |
OnOpen
Occurs when [on open].
Declaration
public event Action<MouseEventArgs, ContextMenuOptions> OnOpen
Event Type
Type | Description |
---|---|
Action<MouseEventArgs, ContextMenuOptions> |