防止在wpf浏览器中右键单击

prevent right click in wpf browser

我想使用 WPF WebBrowser,但用户可以按右键单击打开新选项卡,例如我知道我需要禁用上下文菜单,但我只找到适用于 WinForms Webbrowser 的解决方案。

这是我试过的:webBrowser.ContextMenu.IsEnabled = false

希望能帮到你

这就是我不久前在 WPF 中解决它的方法(从另一个答案得到这段代码,但我没有 link 这个问题):

//Declare
private HTMLDocumentEvents2_Event documentEvents;

//Navigate to a Webpage and create a Eventhandler for LoadCompleted
webBrowser.Navigate(HTML);
webBrowser.LoadCompleted += webBrowser_LoadCompleted;

private void webBrowser_LoadCompleted(object sender, NavigationEventArgs e)
{
   documentEvents = (HTMLDocumentEvents2_Event)webBrowser.Document;
   documentEvents.oncontextmenu += webBrowser_ContextMenuOpening;
}

private bool webBrowser_ContextMenuOpening(IHTMLEventObj pEvtObj)
{
    return false;
}