简体   繁体   English

如何在 C# windows 应用程序中使用 Microsoft Edge WebView2 控件

[英]How can I use the Microsoft Edge WebView2 control in C# windows application

如何使用 Visual Studio 在 C# windows 应用程序中使用 Microsoft Edge WebView2 控件?

Now in 2020 WebView2 supports both WPF and WinForms so you can try to use it in your application.现在在 2020 年,WebView2 同时支持 WPF 和 WinForms,因此您可以尝试在您的应用程序中使用它。

https://docs.microsoft.com/en-us/microsoft-edge/webview2/ https://docs.microsoft.com/en-us/microsoft-edge/webview2/

https://docs.microsoft.com/en-us/microsoft-edge/webview2/gettingstarted/wpf https://docs.microsoft.com/en-us/microsoft-edge/webview2/gettingstarted/wpf

Basically you need to add Nuget package Microsoft.Web.WebView2 and then use WebView2 control.基本上你需要添加 Nuget 包 Microsoft.Web.WebView2 然后使用 WebView2 控件。

The Microsoft Edge WebView2 (powered by Microsoft Edge (Chromium) as the rendering engine) is available on the following programming environments: Win32 C/C++ (GA), .NET Framework 4.6.2 or later, .NET Core 3.1 or later and .NET 5. Microsoft Edge WebView2 (由 Microsoft Edge (Chromium) 作为渲染引擎提供支持)可用于以下编程环境:Win32 C/C++ (GA)、.NET Framework 4.6.2 或更高版本、.NET Core 3.1 或更高版本以及 .网络 5.

Get started with WebView2开始使用 WebView2

  1. Install prerequisites on your machine:在您的机器上安装先决条件:

  2. Create a Windows Forms Application.创建 Windows 窗体应用程序。

  3. Install WebView2 NuGet package in your project.在您的项目中安装 WebView2 NuGet 包

  4. Drop an instance of the WebView2 from toolbox on your form.从表单上的工具箱中删除 WebView2 的实例。

  5. Set the Source property to a valid URL like: https://example.com and run the application.将 Source 属性设置为有效的 URL,例如: https : //example.com并运行应用程序。

More information更多信息

You cannot currently do it without some hacks as it is missing the interfaces.您目前无法在没有一些黑客的情况下做到这一点,因为它缺少接口。 It only support C++ win32 API for the time being.暂时只支持C++ win32 API。 Please see this post for more information https://github.com/MicrosoftEdge/WebViewFeedback/issues/46有关详细信息,请参阅此帖子https://github.com/MicrosoftEdge/WebViewFeedback/issues/46

I don't recommend that you use webview2 at present.我目前不建议您使用 webview2。 This project is now seriously lacking in perfection.这个项目现在严重缺乏完善。 It used to be able to directly call the kernel of the local edge (no beta version), but now it is actually necessary to install the runtime in advance.以前可以直接调用local edge的kernel(没有beta版),但是现在其实需要提前安装runtime了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 WPF 中设置 WebView2 控件的不透明度 - How can I set Opacity of WebView2 control in WPF 如何在控制台应用程序中使用 WebView2 - How do I use WebView2 in a console application 如何从我的 C# 应用程序中检查新 Microsoft Edge Chromium 的版本? - How can I check the version of the new Microsoft Edge Chromium from inside my C# application? 如何在 c# windows 应用程序中使用 RichEdit20W 控件? - How can I use RichEdit20W Control in c# windows application? 如何在Windows Phone 8 C#应用程序中使用WebView控件 - how to use WebView Control in Windows phone 8 C# app 如何在 WPF 中初始化 WebView2? - How can I initialize the WebView2 in WPF? 无法使 WebView2 为 Dotnet 框架 Windows 应用程序工作 - Can't make WebView2 work for Dotnet Framework Windows application C# winform 应用程序 Webview2 webBrowser 提交按钮不起作用 - C# winform Application Webview2 webBrowser Submit button Not Working 我无法从 c# windows ZAC68B62ABFD6A9FE26E8AC4236CCE8 应用程序中捕获 Microsoft Edge url - I am not able to capture Microsoft edge url from c# windows forms application 如何删除 C# WPF 应用程序中的 WebView2 UserDataFolder,BrowserProcessExited 事件不会触发 - How to delete the WebView2 UserDataFolder in C# WPF Application, BrowserProcessExited event does not fire
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM