Пример #1
0
        public WebViewCompatible()
            : base()
        {
            if (WebViewControlHost.IsSupported && WebViewControlHost.CanCreateWebViewControlHost().Result)
            {
                _implementation = new WebViewCompatibilityAdapter();
            }
            else
            {
                _implementation = new WebBrowserCompatibilityAdapter();
            }

            _implementation.Initialize();

            AddChild(_implementation.View);
            _implementation.View.BeginInit();
            _implementation.View.EndInit();
            var binder = new Binding()
            {
                Source = _implementation,
                Path   = new PropertyPath(nameof(Source)),
                Mode   = BindingMode.TwoWay
            };

            BindingOperations.SetBinding(this, SourceProperty, binder);
        }
Пример #2
0
        internal WebView(WebViewControlHost webViewControl)
            : this()
        {
            _webViewControl = webViewControl ?? throw new ArgumentNullException(nameof(webViewControl));
            Process         = _webViewControl.Process;

            EnsureInitialized();
        }
Пример #3
0
 /// <summary>
 /// Releases the unmanaged resources used by the <see cref="System.Windows.Forms.Control" /> and its child controls and optionally releases the managed resources.
 /// </summary>
 /// <param name="disposing"><see langword="true" /> to release both managed and unmanaged resources; <see langword="false" /> to release only unmanaged resources.</param>
 protected override void Dispose(bool disposing)
 {
     try
     {
         if (disposing)
         {
             Close();
             _webViewControl?.Dispose();
             _webViewControl = null;
             Process         = null;
         }
     }
     finally
     {
         base.Dispose(disposing);
     }
 }
Пример #4
0
        /// <summary>
        /// Closes this control.
        /// </summary>
        public void Close()
        {
            var webViewControlAlreadyClosed = _webViewControlClosed;

            _webViewControlClosed = true;

            // Unsubscribe all events:
            UnsubscribeEvents();

            if (!webViewControlAlreadyClosed)
            {
                _webViewControl?.Close();
                _webViewControl?.Dispose();
            }

            _webViewControl = null;
            Process         = null;
        }
Пример #5
0
        /// <summary>
        /// Updates the location and size of <see cref="WebView"/>.
        /// </summary>
        /// <param name="host">A <see cref="WebViewControlHost"/> instance</param>
        /// <param name="bounds">A <see cref="Rectangle"/> containing numerical values that represent the location and size of the control.</param>
        /// <seealso cref="WebViewControlHost.UpdateBounds"/>
        /// <exception cref="ArgumentNullException"><paramref name="host"/> is <see langword="null"/>.</exception>
        /// <remarks><paramref name="bounds" /> is translated into a <seealso cref="Windows.Foundation.Rect(double, double, double, double)"/>.</remarks>
        internal static void UpdateBounds(this WebViewControlHost host, Rectangle bounds)
        {
            Windows.Foundation.Rect CreateBounds()
            {
                return(new Windows.Foundation.Rect(
                           bounds.X,
                           bounds.Y,
                           bounds.Width,
                           bounds.Height));
            }

            if (host is null)
            {
                throw new ArgumentNullException(nameof(host));
            }

            host.UpdateBounds(CreateBounds());
        }
Пример #6
0
 internal WebView(WebViewControlHost webViewControl)
     : this()
 {
     _webViewControl = webViewControl ?? throw new ArgumentNullException(nameof(webViewControl));
     _process        = webViewControl.Process;
 }