Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

209
Visualizações
Overriding Webview2 context menu along with default one

Following the approach mentioned in the below link I was able to override default context menu.

How do you override the ContextMenu that appears when right clicking on WebView2 Control?

I have a question is there a way to show both based on some condition like

  • Normal right-click - Custom Overridden context menu
  • CTRL or SHIFT press + right-click - default context menu
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

That's actually easy, when you have the code from that link.

The contextmenu event derives from MouseEvent, so it has information about the control keys being pressed.

Simply replace the javascript contextmenu handler to:

document.addEventListener('contextmenu', function (event)
{
    if (!event.ctrlKey && !event.shiftKey)
    {
        let jsonObject =
        {
            Key: 'contextmenu',
            Value:
            {
                X: event.screenX,
                Y: event.screenY
            }
        };
        window.chrome.webview.postMessage(jsonObject);
        event.preventDefault();
    }
});

It works so that if a control key is pressed, it does absolutely nothing, which will show the default menu. If no keys are pressed, it sends the coordinates to C# and calls event.preventDefault();.

Note: In the code from that link, I call:

webView21.CoreWebView2.Settings.AreDefaultContextMenusEnabled = false;

Here, you should NOT call that. Instead call event.preventDefault(); in javascript.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda