在Winforms应用程序中将WebBrowser类升级为WebView类 [英] Upgrading WebBrowser class into WebView class in winforms application
问题描述
在我的winforms应用程序中,我使用了WebBrowser
类,该类正在使用IE
浏览器.我想将其更新为WebView
类,以便可以使用Edge
浏览器.这就是为什么我安装软件包Microsoft.Toolkit.Forms.UI.Controls.WebView
的原因.然后,我更改了一些与WebView
兼容的现有代码.但是当我运行该项目时,安装该软件包后发现以下错误.
In my winforms application, I used WebBrowser
class which is using IE
browser. I want to update it into WebView
class so that I can use Edge
browser. That's why I installed packages Microsoft.Toolkit.Forms.UI.Controls.WebView
. Then I changed some existing code which is compatible with WebView
. But when I ran the project, I found the below errors after installing that package.
其中的项目"C:\ Projects \ windows-v2 \ packages \ System.Runtime.WindowsRuntime.4.6.0 \ build \ net461 .... \ ref \ netstandard2.0 \ System.Runtime.WindowsRuntime.dll"项目列表"ReferencePath"没有为元数据"CopyLocal"定义值.为了使用此元数据,请通过指定%(ReferencePath.CopyLocal)对其进行限定,或者确保此列表中的所有项目都为此元数据定义了一个值.
The item "C:\Projects\windows-v2\packages\System.Runtime.WindowsRuntime.4.6.0\build\net461....\ref\netstandard2.0\System.Runtime.WindowsRuntime.dll" in item list "ReferencePath" does not define a value for metadata "CopyLocal". In order to use this metadata, either qualify it by specifying %(ReferencePath.CopyLocal), or ensure that all items in this list define a value for this metadata.
推荐答案
To use a WebViewCompatible
control in a Windows Forms application:
- 安装软件包
Microsoft.Toolkit.Forms.UI.Controls.WebView
- 右键单击工具箱中的空白区域→选择选择项目→从选择工具箱项目→选择 .NET Framework组件选项卡→单击浏览→浏览软件包文件夹,然后选择
Microsoft.Toolkit.Forms.UI.Controls.WebView
dll→单击打开→单击确定 - 将
WebViewCompatible
控件的实例拖放到窗体上. -
在
Load
事件中或InitializeComponent
之后的构造函数中,添加代码以导航到所需的地址:
- Install package
Microsoft.Toolkit.Forms.UI.Controls.WebView
- Right click on an empty area in Toolbox → select Choose Items → From the Choose Toolbox Items → choose .NET Framework Component tab → Click on Browse → Browse the package folder and choose
Microsoft.Toolkit.Forms.UI.Controls.WebView
dll → Click Open → Click OK - Drop an instance of
WebViewCompatible
control on the form. In the
Load
event or in constructor afterInitializeComponent
add code to navigate to the address you want:
webViewCompatible1.Navigate("https://www.google.com");
这篇关于在Winforms应用程序中将WebBrowser类升级为WebView类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!