x
Main Site login Signup

How to edit or set current context menu in WebViewType.Window?

My context menu in code behind has worked in WebViewType.Offscreen, but not in WebViewType.Window. How can i do to control current context menu in WebViewType.Window?

Thank,

Here is my code behind in WebViewType.Offscreen:

         void Html5_PreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e)
         {
                     switch (e.RightButton)
                     {
                         // Right mouse click
                         case MouseButtonState.Pressed:
                           {
                             ContextMenu myContextMenu = new ContextMenu();
 
                             MenuItem reload = new MenuItem();
                             reload.Header = "Reload (F5)";
                             reload.PreviewMouseLeftButtonDown += reload_PreviewMouseLeftButtonDown;
 
                             myContextMenu.Items.Add(reload );
                             myContextMenu.IsOpen = true;
                             break;
                         }
                 }
         }
asked Sep 06, 2013 at 05:34 AM avatar image nickcarter 132
more ▼
(comments are locked)
10|1100 characters needed characters left

3 answers: sort voted first

Thank guys! I have solved my trouble though it's not great :) It's so easy: In code behind, I create a new ContextMenu, if currentContextMenu.Info.HasLinkURL, I set Handled = true and open new ContextMenu

     void Html5_ShowContextMenu(object sender, Awesomium.Core.ContextMenuEventArgs e)
     {
         ContextMenu myContextMenu = new ContextMenu();


         MenuItem openLinkInNewTab = new MenuItem();
         openLinkInNewTab.Header = "Open Link In New Tab";
         openLinkInNewTab.PreviewMouseLeftButtonDown += openLinkInNewTab_PreviewMouseLeftButtonDown;


         if (e.Info.HasLinkURL)
         {
             
             e.Handled = true;
             myContextMenu.Items.Add(new Separator());
             myContextMenu.Items.Add(openLinkInNewTab);
             myContextMenu.IsOpen = true;
         }
     }
answered Sep 08, 2013 at 08:52 AM avatar image nickcarter 132
more ▼
(comments are locked)
10|1100 characters needed characters left

I haven't come across this particular situation, however popups (contextmenu's) are displayed after the ShowContextMenu event. This should allow a chance to override the items that display. But don't quote me on that second bit.

Update

Here's an example of overriding the items of several types of popups. (As you can see, a separator is used because sometimes these can appear in the same context menu together (if an image is under the mouse the ContextMenuImageItemsArray will be visible along with ContextMenuPageItemsArray and so on)

Keep in mind this code is bound to Commands explicit to my application

     <!-- We override the items that appear when we right-click an image -->
     <x:Array x:Key="{x:Static awe:WebControl.ContextMenuImageItemsArrayRecourceKey}" Type="{x:Type DependencyObject}">
         <MenuItem Command="{x:Static local:WebBrowser.SaveImageAs}" CommandParameter="{Binding SourceURL}"/>
         <MenuItem Header="Copy image" Command="{x:Static awe:WebControlCommands.CopyImage}"/>
         <MenuItem Command="{x:Static local:WebBrowser.CopyImageURL}" CommandParameter="{Binding SourceURL}"/>
         <Separator />
     </x:Array>
 
     <!-- We override the items that appear when we right-click a link in a page -->
     <x:Array x:Key="{x:Static awe:WebControl.ContextMenuLinkItemsArrayRecourceKey}" Type="{x:Type DependencyObject}">
         <MenuItem Command="{x:Static local:WebBrowser.OpenTab}" CommandParameter="{Binding LinkURL}"/>
         <MenuItem Command="{x:Static local:WebBrowser.OpenWindow}" CommandParameter="{Binding LinkURL}"/>
         <MenuItem Header="Copy link address" Command="{x:Static awe:WebControlCommands.CopyLinkAddress}" />
         <Separator />
     </x:Array>
     
     <!-- We override the items that appear when we right-click a page, to add the "Show Source Code" item. -->
     <x:Array x:Key="{x:Static awe:WebControl.ContextMenuPageItemsArrayRecourceKey}" Type="{x:Type DependencyObject}">
         <MenuItem Header="Back" Command="BrowseBack" />
         <MenuItem Header="Forward" Command="BrowseForward" />
         <MenuItem Header="Refresh" Command="Refresh" />
         <Separator />
         <MenuItem Command="{x:Static local:WebBrowser.ViewSource}" CommandParameter="{Binding PageURL}"/>
         <Separator />
         <MenuItem Command="Print" />
         <Separator />
         <MenuItem Header ="Select all" Command="SelectAll" />
     </x:Array>
answered Sep 06, 2013 at 01:40 PM avatar image SilverX 676
more ▼
(comments are locked)
avatar image nickcarter Sep 07, 2013 at 04:33 AM

I found your example code in here

http://answers.awesomium.com/questions/2697/how-to-save-an-image-from-webpage.html

But i don't know how to show it in code behind and how to add or edit an item (It's only able to overide, isn't it?).

avatar image SilverX Sep 07, 2013 at 05:02 AM

Well, if you look at the TabbedWPFSample, it shows a couple types of menu items you can override. These items are added/removed depending on what role they play. The example I posted to you is how you display custom items when an image is right-clicked. You will notice the other items still exist (like refresh etc).

Updated my answer.

avatar image nickcarter Sep 08, 2013 at 05:42 AM

So, I can not add another item? (Not overide) :( If it's right, do you know how to display VLC Plugin in WebViewType.Offscreen? (In default, VLC Plugin only displays in WebViewType.Window)

avatar image nickcarter Sep 08, 2013 at 09:01 AM

I have solved my trouble (In my answer). Do you know how to remove or disable an item in code behind?

10|1100 characters needed characters left

i really need your help, i have tried your solutions but am having errors in visual studio how do i go about it, earlier i just copied and pest in awesomium code bt i have lots of errors i want to remove the "Copy Link Address and the Select All"

Please help

answered May 05, 2016 at 12:59 AM avatar image derickarts 0
more ▼
(comments are locked)
10|1100 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.