Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use WebKit browser control in WPF

Tags:

c#

.net

wpf

webkit

I want to use WebKit browser control in my WPF application. However, I am not able to add it in design time. Even if I add the WebKit into toolbox it is disabled state.

My question is how to use that control during design time on WPF form?

Thanks, Omkar

like image 262
Omkar Avatar asked Nov 05 '22 05:11

Omkar


1 Answers

As explained in http://msdn.microsoft.com/en-us/library/ms742735(v=vs.110).aspx , you should first create a WPF grid in your XAML file.

<Grid x:Name="grdBrowserHost">
</Grid>

And add a .NET WebKit in the WPF form by inserting this code into your C# source.

System.Windows.Forms.Integration.WindowsFormsHost host =new System.Windows.Forms.Integration.WindowsFormsHost();

// Create the ActiveX control.
WebKit.WebKitBrowser browser = new WebKit.WebKitBrowser();
browser.Navigate("http://www.google.com");

// Assign the ActiveX control as the host control's child.
host.Child = browser;

// Add the interop host control to the Grid 
// control's collection of child controls. 
grdBrowserHost.Children.Add(host);

Do not forget to include these references

System.Windows.Forms

WindowsFormsIntegration

in your project.

Hope this help.

like image 109
craxidile Avatar answered Nov 09 '22 10:11

craxidile