private void Initialize() { Verify.AreEqual(_initializationState, InitializationState.IsInitializing); Verify.IsFalse(DesignMode); // This is causing freezing if (!DesignMode) { OSVersionHelper.ThrowIfBeforeWindows10April2018(); if (!WebViewControlInitialized) { Verify.IsNull(Process); // Was not injected via ctor, create using defaults var options = new Interop.WinRT.WebViewControlProcessOptions() { PrivateNetworkClientServerCapability = (Interop.WinRT.WebViewControlProcessCapabilityState)(_delayedPrivateNetworkEnabled ? WebViewControlProcessCapabilityState.Enabled : WebViewControlProcessCapabilityState.Disabled), EnterpriseId = _delayedEnterpriseId, Partition = _delayedPartition }; Process = new WebViewControlProcess(options); _webViewControl = Process.CreateWebViewControlHost(Handle, ClientRectangle); SubscribeEvents(); // Set values. They could have been changed in the designer IsScriptNotifyAllowed = _delayedIsScriptNotifyAllowed; IsIndexedDBEnabled = _delayedIsIndexDbEnabled; IsJavaScriptEnabled = _delayedIsJavaScriptEnabled; // This will cause a navigation Source = _delayedSource; } else { // Already provided control SubscribeEvents(); } _webViewControl.IsVisible = true; } _initializationState = InitializationState.IsInitialized; }
/// <summary> /// Creates a <see cref="IWebView"/> within the context of <paramref name="process"/>. /// </summary> /// <param name="process">An instance of <see cref="WebViewControlProcess" />.</param> /// <param name="hostWindowHandle">The host window handle.</param> /// <param name="bounds">A <see cref="Rect" /> containing numerical values that represent the location and size of the control.</param> /// <returns>An <see cref="IWebView" /> instance.</returns> /// <exception cref="ArgumentNullException"> /// <paramref name="hostWindowHandle"/> is equal to <see cref="IntPtr.Zero"/>, or /// <paramref name="process"/> is <see langword="null" />. /// </exception> internal static IWebView CreateWebView( this WebViewControlProcess process, IntPtr hostWindowHandle, Rect bounds) { if (process is null) { throw new ArgumentNullException(nameof(process)); } if (hostWindowHandle == IntPtr.Zero) { throw new ArgumentNullException(nameof(hostWindowHandle)); } return(new WebView(process.CreateWebViewControlHost(hostWindowHandle, bounds))); }
protected override void When() { _webView2 = new UI.Controls.WinForms.WebView(WebViewControlProcess.CreateWebViewControlHost(Form.Handle, Form.ClientRectangle)); }