c# - Custom context menu for WPF WebBrowser Control -


hi need create custom context menu web browser control in wpf. here xaml code not working:

<webbrowser x:name="emailbox"  ap:browserbehavior.htmlstring="{binding message, mode=oneway}">     <webbrowser.contextmenu>         <contextmenu>             <menuitem header="copy" command="applicationcommands.copy"/>             <menuitem header="copy customer reference id"                    command="{binding copyid}"                   commandparameter="{binding relativesource={relativesource findancestor, ancestortype={x:type contextmenu}},                    path=placementtarget.selection.text}">                 <menuitem.icon>                     <image source="{staticresource copyimagesource}" width="16" />                 </menuitem.icon>             </menuitem>             <menuitem header="copy comments"                   command="{binding copytocommentscommand}"                   commandparameter="{binding relativesource={relativesource findancestor, ancestortype={x:type contextmenu}},                    path=placementtarget.selection.text}">                 <menuitem.icon>                     <image source="{staticresource notecopyi}" width="16" />                 </menuitem.icon>             </menuitem>         </contextmenu>     </webbrowser.contextmenu> </webbrowser> 

i copied context menu code somewhere else. works in other controls not webbrowser control. possible make work?

no, it's not possible make work.
webbrowser control thin wrapper around native webbrowser activex component, part of internet explorer subsystem. hosted in it's own window host (wpf window , webbrowser have different hwnds), wpf knows focus entering , leaving webbrowser, has no knowledge of keyboard/mouse events. also, there called 'airspace problem': wpf-rendered , native regions of screen area cannot overlap.
therefore cannot use wpf contextmenu webbrowser, because:

  1. wpf doesn't recieve mouse right click event open context menu
  2. wpf cannot draw context menu above webbrowser

also, don't think there easy way emulate contextmenu html/js in browser's content - recall, activex component uses ie5 (quirk) rendering mode, , not possible change without changing registry files.
can try use activex api webbrowser.document object disable native context menu , draw 1 through winapi, not easy task.
so, recommend other, pure-wpf browser controls or html renderers, such awesomium


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -