> For the complete documentation index, see [llms.txt](https://docs.gapvelocity.ai/webmap-for-blazor-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.gapvelocity.ai/webmap-for-blazor-documentation/blazor-ai-migrator/dcp-desktop-compatibility-library/contextmenustrip.md).

# ContextMenuStrip

The ContextMenuStrip implementation in the BlazorDCP project provides a seamless bridge between Windows Forms ContextMenuStrip functionality and Blazor applications using Telerik UI components. This implementation maintains full compatibility with existing Windows Forms event handling patterns while providing modern web-based context menu experiences.

### Architecture Components

1. **Core Model Class (Gap.Blazor.ContextMenuStrip)**

Location: src\Gap.Blazor\Controls\\[ContextMenuStrip.cs](http://contextmenustrip.cs)

```csharp
/// <summary>
/// ContextMenuStrip model implementation.
/// </summary>
/// <mapfrom>System.Windows.Forms.ContextMenuStrip</mapfrom>
public class ContextMenuStrip : ToolStripDropDownMenu
{
    public ContextMenuStrip(IContainer container) { /* ... */ }
    public ShowEventHandler ShowEventHandler { get; set; }
    public void Show(Control control, Point position) { /* ... */ }
    private void OnShow(ShowEventArgs e) { /* ... */ }
}

```

#### Key Features:

* Windows Forms Compatibility: Inherits from ToolStripDropDownMenu maintaining API compatibility
* Event-Driven Architecture: Uses ShowEventHandler for display coordination
* Position-Aware Display: Supports precise positioning via Point coordinates
* Cancellable Events: Implements Opening event with CancelEventArgs for conditional display

2. **Blazor Component (WMContextMenuStrip)**

Location: src\Gap.Blazor.Components\Components\ContextMenuStrip\WMContextMenuStrip.razor

```html
<TelerikContextMenu @ref="@TemplateContextMenu" 
                   Data="@this.menuItems" 
                   ItemsField="SubItems" 
                   OnClick="@((MenuItem item) => OnClickHandler(item))">
    <ItemTemplate>
        <WMToolStripMenuItem UseDesignerStyles="@this.UseDesignerStyles" 
                           model="@context.ToolStripItem" />
    </ItemTemplate>
</TelerikContextMenu>

```

#### Component Properties:

* Model Integration: Directly binds to ContextMenuStrip model instance
* Hierarchical Support: Handles nested menu items through SubItems field
* Template-Based Rendering: Uses WMToolStripMenuItem for consistent item display
* Event Bridging: Connects Telerik events to Windows Forms event handlers.

#### Event flow architecture

<figure><img src="/files/x4wMvGb8JidHJOoooiuw" alt=""><figcaption></figcaption></figure>

### Browser Context Menu Prevention

Challenge: Browser's native right-click context menu interferes with custom implementation.

Solution: Selective event prevention using JavaScript:

```javascript
document.addEventListener('contextmenu', function (event) {
    if(event.target.parentElement.className.indexOf("cssclassofitemtopreventbrowserctxmenu") > -1 || 
       event.target.parentElement.className.indexOf("k-child-animation-container") > -1){
        event.preventDefault();
        event.stopPropagation();
    }
});

```

\ <br>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.gapvelocity.ai/webmap-for-blazor-documentation/blazor-ai-migrator/dcp-desktop-compatibility-library/contextmenustrip.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
