c# - WPF中如何使用WebKit浏览器控件

标签 c# .net wpf webkit

我想在我的 WPF 应用程序中使用 WebKit 浏览器控件。但是,我无法在设计时添加它。即使我将 WebKit 添加到工具箱中,它也处于禁用状态。

我的问题是如何在 WPF 窗体的设计时使用该控件?

谢谢, 欧姆卡尔

最佳答案

http://msdn.microsoft.com/en-us/library/ms742735(v=vs.110).aspx 中所述,您应该首先在 XAML 文件中创建一个 WPF 网格。

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

并通过将这段代码插入到您的 C# 源代码中,以 WPF 形式添加一个 .NET WebKit。

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);

不要忘记包含这些引用

System.Windows.Forms

WindowsFormsIntegration

在你的项目中。

希望这对您有所帮助。

关于c# - WPF中如何使用WebKit浏览器控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4386422/

相关文章:

c# - Buddy 类到底是什么?如何使用它向现有类添加注释?

c# - 方法重载和代码重复提升

c# - 从代码隐藏运行 javascript 函数

.net - WPF 错误 CS0433

wpf - DataGrid , TextBox - 绑定(bind)和即时更新

WPF 调度控制

c# - Interlocked 是否保证对 C# 中其他线程的可见性,还是我仍然必须使用 volatile?

.net - 如何在 AppVeyor 中使用 dotnet pack?

.net - F# 编译器是单程编译器吗?

c# - 在.NET中读取佳能CR2原始图像文件