开发者

How to use WebKit browser control in WPF

I want to use WebKit browser control in my WPF application. However, I am not able t开发者_开发知识库o 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


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.


I'm guessing it's an activex control. Try this: http://msdn.microsoft.com/en-us/library/ms742735.aspx


One of the best approaches for hosting Webkit (or Blink) in a WPF application presently (as of October 2017) seems to be with the Awesomium project which has first-class wrapper libraries for various platforms, including WinForms and WPF.

I advise against using any web-browser control inside a System.Windows.Forms.Integration.WindowsFormsHost in a WPF application because, at least, of the added layers of indirection and unpredictable behaviour in High-DPI contexts - I'm sure there are other reasons too.

Note that Awseomium is not true open-source or Free Software. If your company makes more than $100k USD in profit per year then for commercial applications there is a $2900 USD per-title license fee.

With that caveat out the way, getting started with Awesomium in WPF is straightforward:

  1. Download the Awesomium SDK. (As of October 2017 the Awesomium download page is unavailable for an upgrade, but the SDK is still available to download from the Internet Archive and other places online).
  2. The SDK installer will register the Awesomium assemblies in the GAC for you, so they'll appear in the WPF (and WinForms) Toolbox Add/Remove Items window.
  3. Open your WPF project in Visual Studio and open a XAML design document.
  4. Open the Visual Studio Toolbox and open the Add/Remove Items window and add the Awesomeium WPF controls from the Awesomium.Windows.Controls.dll assembly loaded in your GAC. You'll probably only want the WebControl control (Awesomium.Windows.Controls.WebControl).
  5. Drag and drop the control from the Toolbox onto your design surface - Visual Studio will automatically update your project to add the references to the Awesomeium assemblies.

Note there are other wrapper libraries around Chromium - I don't meant to endorse Awesomium specifically, but I had a good time with it when I used it in a recent project.

Another popular library is CefSharp which is BSD licensed, which will be more palatable compared to Awesomium's, but (as far as I can tell) does not distribute an SDK installer which handles Visual Studio Toolbox integration for you - but it looks like you only need to manually add a reference to the CefSharp.Wpf.dll assembly and add the elements to your WPF project (using the XAML editor, not the Toolbox - which you should be doing anyway).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜