gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 23:41:59 26 4
gpt4 key购买 nike

我想在我的 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com