显式初始化
CoreWebView2
,请尝试以下操作:
添加以下Imports语句
:
-
Imports Microsoft.Web.WebView2.Core
-
Imports Microsoft.Web.WebView2
-
Imports System.IO
初始化EcoreWebView2Async
:
Private Async Function InitializeCoreWebView2Async(Optional userDataFolder As String = "") As Task
Dim options As CoreWebView2EnvironmentOptions = Nothing
Dim cwv2Environment As CoreWebView2Environment = Nothing
'it's recommended to create the userDataFolder in the same location
'that your other application data is stored (ie: in a folder in %APPDATA%)
'if not specified, we'll create a folder in %TEMP%
If String.IsNullOrEmpty(userDataFolder) Then
userDataFolder = Path.Combine(Path.GetTempPath(), System.Reflection.Assembly.GetExecutingAssembly().GetName().Name)
End If
'create WebView2 Environment using the installed or specified WebView2 Runtime version.
'cwv2Environment = Await CoreWebView2Environment.CreateAsync("C:\Program Files (x86)\Microsoft\Edge Dev\Application\1.0.1054.31", userDataFolder, options)
cwv2Environment = Await CoreWebView2Environment.CreateAsync(Nothing, userDataFolder, options)
'initialize
Await WebView21.EnsureCoreWebView2Async(cwv2Environment)
End Function
笔记
:如果希望显式初始化
CoreWebView2
,必须在设置
Source
房地产
WebView2
控制
用法
:
Await InitializeCoreWebView2Async(Path.Combine("C:\Temp", System.Reflection.Assembly.GetExecutingAssembly().GetName().Name))
如果您在表单(例如:Form1.vb)中调用它,那么您应该执行以下操作:
Private Async Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
System.Diagnostics.Debug.WriteLine("MS Edge Version: " & CoreWebView2Environment.GetAvailableBrowserVersionString())
'initialize
'Await InitializeCoreWebView2Async()
Await InitializeCoreWebView2Async(Path.Combine("C:\Temp", System.Reflection.Assembly.GetExecutingAssembly().GetName().Name))
'ToDo: add desired code, such as navigating to a URL
End Sub
笔记
:
CoreWebView2CreationProperties
可能也有兴趣。
资源
: