Skip to content

Feature Request - Ability to set WPF context menu's style #5242

Open

Description

@chucker

Describe the solution you'd like
I moved from IContextMenuHandler to CefSharp.Wpf.Handler.ContextMenuHandler in order to avoid #1882.

As a result, the context menu now has the default WPF styling, which doesn't really fit Chrome or modern Windows.

I would like to be able to set the context menu's Style property; however, the context menu is instantiated ad-hoc, so this doesn't seem possible. I.e., I would like

  • either a property ContextMenuStyle on CefSharp.Wpf.ChromiumWebBrowser to set the style beforehand, then if set, have CefSharp.Wpf.Handler.ContextMenuHandler apply it
  • or an event ContextMenuCreated in CefSharp.Wpf.Handler.ContextMenuHandler which I can listen to

Describe alternatives you've considered

  • implementing IContextMenuHandler myself (or inheriting from CefSharp.Wpf.Handler.ContextMenuHandler. However, that seems like a lot of error-prone work.
  • using CefSharp.Wpf.Handler.ContextMenuHandler but overriding RunContextMenu to grab the created ContextMenu. This doesn't (seem to) work reliably due to timing issues.

Checklist:

  • I have reviewed the CEF API and have confirmed the feature I'm requesting is possible.
    - [ ] The Feature I'm requesting is an improvement to Async Javascript Binding (No new feature are being added to the Sync Javascript binding)
    - [ ] An open PR exists on the CEF Pull Requests and I'd like to propose this feature is added to CefSharp when/if it's merged.

Activity

  1. amaitland commented on May 8, 2026

    @amaitland
    Member

    As a result, the context menu now has the default WPF styling, which doesn't really fit Chrome or modern Windows.

    I'd generally expect whatever theme you were using to apply it's styling to the context menu and they'd all be consistent throughout the application. That or you just override the default context menu styling so they're all consistent.

    The WPF Example uses https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit which provides styling for the context menu.

    I.e., I would like

    • either a property ContextMenuStyle on CefSharp.Wpf.ChromiumWebBrowser to set the style beforehand, then if set, have CefSharp.Wpf.Handler.ContextMenuHandler apply it
    • or an event ContextMenuCreated in CefSharp.Wpf.Handler.ContextMenuHandler which I can listen to

    I don't have any objection to something being added, though I'm not sure about either of these. Events are a hassle, making sure you don't end up with a memory leak. A simple protected virtual method on ContextMenuHandler that you to override the creation of the context menu is likely a lot simpler.

    Your welcome to submit a PR for discussion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions