In this video, we'll walk you through process of working with context menus in DotNetBrowser.
Download DotNetBrowser form the Visual Studio Gallery: https://goo.gl/Nj3GF4
Get a free 30-days DotNetBrowser trial licence: https://goo.gl/rfod5B
About DotNetBrowser:
DotNetBrowser allows embedding a Chromium-based browser to your .NET app to display and process HTML5, CSS3, JavaScript, Flash etc.
To learn more about DotNetBrowser go to https://goo.gl/xMDZh9
For more ideas on using an advanced browser-component in your .NET application, please see examples on DotNetBrowser support site https://goo.gl/SwuRWm
Previous tutorials:
How to get DotNetBrowser Evaluation Licence: • How to get DotNetBrowser Evaluation Licence
How to Add a Browser Component to WPF Application: • How to Add a Browser Component to WPF Appl...
How to Create HTML UI for WPF Application Using DotNetBrowser: • How to Create HTML UI for WPF Application ...
How to Add a Browser Component to a Windows Forms Application: • How to Add a Browser Component to a Window...
Executing JavaScript from the .NET Side Using DotNetBrowser: • Executing JavaScript from the .NET Side Us...
Injecting a .NET Object into JavaScript Using DotNetBrowser: • Injecting a .NET Object into JavaScript Us...
DotNetBrowser – a Webkit Сontrol for C# WPF and Windows Forms: • DotNetBrowser – a Webkit Сontrol for C# WP...
Getting or Setting HTML Content in DotNetBrowser: • Getting or Setting HTML Content in DotNetB...
Transcript:
00:06 First of all we need to create a WPF project. Then add the DotNetBrowser NuGet package and the valid licenсe file as embedded resources.
You can find detailed instructions in the previous tutorials.
00:17 Now We Need to Mark up the MainWindow.
00:19 Let’s add the Xml Namespace to the DotNetBrowser.Wpf library in the MainWindow.xaml .
00:27 After that create the WPFBrowserView component and define its name and the initial URL.
00:43 It’s time to implement the MainWindow Behaviour.
00:45 Create the SearchContextMenuHandler class and inherit it from the DotNetBrowser.ContextMenuHandler interface.
00:56 Generate the stubs for the methods which are declared in the interface.
00:59 In this handler we will need to use the window’s dispatcher, so let’s define the parentWindow field.
01:05 Fill the parentWindow field from the constructor.
01:08 Now go to the ShowContextMenu method and open the parentWindow.Dispatcher.BeginInvoke instruction.
01:22 Create the menu item and set its Header.
01:38 Next we need to define whether this command is enabled. It will be enabled if any text in the browser is selected.
01:50 Define the menu item click handler.
02:07 In this handler we need to generate the URL which will be opened after the command execution. Let’s use Bing for the search. The selected text will be the query argument for this service.
02:25 Then execute the JavaScript which will open the new browser window with the generated URL as the initial address.
02:46 After defining the menu item click handler create the System.Windows.Controls.ContextMenu instance. Using the WPF ContextMenu component requires specifying the full name because it conflicts with the DotNetBrowser ContextMenu component.
03:06 Add the searchMenuItem to the context menu items.
03:13 Finally, open the context menu.
03:17 The last step is setting the SearchContextMenuHandler instance as the browser’s context menu handler. Inside the MainWindow constructor after the InitializeComponent method call, fill the BrowserView.Browser.ContextMenuHandler property value with the new instance of the SearchContextMenuHandler class.
03:33 Build and launch
#WorkingWithContextMenus
#DotNetBrowser
#EmbeddedBrowsers