Exemplo n.º 1
0
        /// <summary>
        /// Programatically initialize the WebView2Wrapper component.
        /// </summary>
        public async void InitializeWebView(DockPanel docker)
        {
            _webView = new Microsoft.Web.WebView2.Wpf.WebView2();

            // clear everything in the WPF dock panel container
            docker.Children.Clear();
            docker.Children.Add(_webView);

            // initialize the webview 2 instance
            try
            {
                _webView.CoreWebView2InitializationCompleted += OnWebViewInitializationCompleted;
                CoreWebView2Environment env = await CoreWebView2Environment.CreateAsync(null, ExecutingLocation);

                await _webView.EnsureCoreWebView2Async(env);

                _webView.WebMessageReceived  += OnWebViewInteraction;
                _webView.NavigationCompleted += OnWebViewNavigationCompleted;
                //InitializeDevToolsProtocolHelper();
                //SubscribeToDocumentUpdated();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
 /// <summary>
 /// WebBrowserLogin Load event handler
 /// </summary>
 public void WebBrowserLogin_Load(object sender, EventArgs e)
 {
     DoNavigation = (Action) delegate
     {
         webView.Source = new Uri(this.url.ToString(), UriKind.Absolute);
     };
     CountOfNavigationStartingEvents              = 0;
     webView.CoreWebView2InitializationCompleted += WebView_CoreWebView2Ready;
     WebViewInitializeTask = webView.EnsureCoreWebView2Async();
 }
Exemplo n.º 3
0
        public async Task Render(UserControls.SnippetDocumentControl snippetDocControl)
        {
            // load the document text into the internet explorer browser
            if (_myBrowser != null)
            {
                try
                {
                    // see info on how to navigate here: https://stackoverflow.com/questions/63116740/why-my-corewebview2-which-is-object-of-webview2-is-null
                    await _myBrowser.EnsureCoreWebView2Async();
                    await SetupDocumentInteraction();

                    string url = snippetDocControl.EnsureServer();
                    _myBrowser.CoreWebView2.Navigate(url);
                }
                catch (Exception ex)
                {
                    System.Windows.MessageBox.Show(string.Format("Problem with IE browser loading html.  Exception: {0}", ex), "IE HTML Load Exception", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error);
                }
            }
        }