locked
WPF Sp1 WebBrowser control - disable context menu RRS feed

  • Question

  • Hi

     

    I am using WebBrowser control from WPF Sp1, I am providing back/forward navigation programatically, that works fine (pretty cool compared to the Frame control where there is no journal access). But I can't diable the context menu that appears on right click in the WebBrowser control. I don't seem to get the mouse events on the WebBrowser control and the ContextMenu class seems to also not work with WebBrowser .

     

    How can  I disable context menu for WebBrowser control?

     

    Shilpa

    Tuesday, May 13, 2008 10:18 PM

Answers

  • The WPF WebBrowser control wraps the IE WebOC (WebBrowser control).  You won't receive mouse events in WPF when you're over it.  The context menu comes from IE so it's not a WPF ContextMenu.

     

    If what you're displaying in the WebBrowser is HTML content you control, you can change the body tag to look like this:

    <body oncontextmenu="return false;">

     

    That will stop the context menu from showing up.

     

    If you're hosting the WebBrowser in a full trust .xbap or a standalone app, there's a registry key that can be set to disable the browser context menu, but it will affect Internet Explorer as well as the browser control, so I'm not sure I'd recommend it.  If you really want to try it, set the regkey:

    HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Internet Explorer\Restrictions\NoBrowserContextMenu

     to the DWORD value 1.

     

    Andre

    Wednesday, May 14, 2008 2:14 AM