Windows 窗体中的 WebView2 不导航?

Jiale Xue - MSFT 36,471 信誉分 Microsoft 供应商
2024-03-20T07:12:27.9+00:00

在 Windows 窗体应用中的 WebView2 入门步骤 3.4 程序编译正常,但未导航到 https://www.microsoft.com。 它也不会在 goButton_Click 上导航。 代码下面,Form1.Designer.cs后跟 Form1.cs 。

            this.webView.BackColor = System.Drawing.SystemColors.ActiveCaption;
            this.webView.Location = new System.Drawing.Point(12, 55);
            this.webView.Name = "webView";
            this.webView.Size = new System.Drawing.Size(1115, 426);
            this.webView.Source = new System.Uri("https://www.microsoft.com", System.UriKind.Absolute);
            this.webView.TabIndex = 0;
            this.webView.Text = "webView";
            this.webView.ZoomFactor = 1D;

/////////////////////////////////////////////////////////////////////

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.Web.WebView2.Core;

namespace WinFormsGettngStarted
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            this.Resize += new System.EventHandler(this.Form_Resize);
            webView = new Microsoft.Web.WebView2.WinForms.WebView2();

        }
        private void Form_Resize(object sender, EventArgs e)
        {
            webView.Size = this.ClientSize - new System.Drawing.Size(webView.Location);
            goButton.Left = this.ClientSize.Width - goButton.Width;
            addressBar.Width = goButton.Left - addressBar.Left;
        }
            private void goButton_Click(object sender, EventArgs e)
        {
            if (webView != null && webView.CoreWebView2 != null)
            {
                webView.CoreWebView2.Navigate(addressBar.Text);
            }
        }

        private void addressBar_TextChanged(object sender, EventArgs e)
        {

        }

    }
}

Note:此问题总结整理于: WebView2 in Windows Forms does not Navigate ?

Windows 窗体
Windows 窗体
一组用于开发图形用户界面的 .NET Framework 托管库。
99 个问题
0 个注释 无注释
{count} 票

接受的答案
  1. Hui Liu-MSFT 41,331 信誉分 Microsoft 供应商
    2024-03-20T08:04:16.8633333+00:00

    我按照本文档进行了测试,我遇到了与您相同的问题。

    我尝试下载并安装 Microsoft Edge Beta 频道而不是 Microsoft Edge Canary 频道,它工作正常。

    因此,您可以尝试 Microsoft Edge Beta 频道


    如果答案是正确的,请点击“接受答案”并点赞。 如果您对此答案还有其他疑问,请点击“评论”。

    注意:如果您想接收相关电子邮件,请按照我们的文档中的步骤启用电子邮件通知 此线程的通知。

    1 个人认为此答案很有帮助。
    0 个注释 无注释

0 个其他答案

排序依据: 非常有帮助