0

I have a question in WebView2 I have loaded a page, if its content changes I need to reload?

In previous project using WebBrowser.DocumentCompleted, now is not using WebBrowser.

Thank you

Jan Grepl
  • 1
  • 1
  • 3
    Have you looked at the documentation? I woukd think navigationcompleted is the event to try. – Andy Feb 25 '21 at 17:48

1 Answers1

0

I would suggest you try the following in you WPF project.

In your window XAML

<WV:WebView2 x:Name="WebView"
                     Source="https://YOURURL" CoreWebView2InitializationCompleted="WebView_CoreWebView2InitializationCompleted" />

In your code behind use somthing like this. You need to wait for the CoreWebView2 to object to be created.

        private void WebView_CoreWebView2InitializationCompleted(object sender, Microsoft.Web.WebView2.Core.CoreWebView2InitializationCompletedEventArgs e)
        {
            if (e.IsSuccess) System.Diagnostics.Debug.Print("WebView is ready for native window.");
            this.WebView.CoreWebView2.NavigationStarting += CoreWebView2_NavigationStarting;
            this.WebView.CoreWebView2.NavigationCompleted += CoreWebView2_NavigationCompleted;
        }

        private void CoreWebView2_NavigationCompleted(object sender, Microsoft.Web.WebView2.Core.CoreWebView2NavigationCompletedEventArgs e)
        {
            Debug.Print("++++++++++++++++++++++++NavigationCompleted++++++++++++++++++++++++++++");
            Debug.Print("NavigationId: " + e.NavigationId.ToString());
            Debug.Print("URL: " + this.WebView.CoreWebView2.Source);
            Debug.Print("++++++++++++++++++++++++++++++++++++++++++++++++++++");
        }

        private void CoreWebView2_NavigationStarting(object sender, Microsoft.Web.WebView2.Core.CoreWebView2NavigationStartingEventArgs e)
        {
            Debug.Print("#######################NavigationStarting##############################");
            Debug.Print("NavigationId: " + e.NavigationId.ToString());
            Debug.Print("URL: " + e.Uri);
            Debug.Print("#####################################################");
        }
darbid
  • 2,545
  • 23
  • 55