Beispiel #1
0
        /// <summary>
        /// Creates a <see cref="IWebView"/> within the context of <paramref name="process"/> using the <paramref name="visual"/> to create a HWND.
        /// </summary>
        /// <param name="process">An instance of <see cref="WebViewControlProcess" />.</param>
        /// <param name="visual">A <see cref="Visual"/> instance in which to create a HWND.</param>
        /// <returns>An asynchronous operation that completes with a <see cref="IWebView"/>.</returns>
        /// <remarks>
        /// The bounds to draw the <see cref="WebView"/> are determined by the height and width of the <paramref name="visual"/>.
        /// </remarks>
        /// <seealso cref="CreateWebViewAsync(WebViewControlProcess,IntPtr,Rect)"/>
        internal static Task <IWebView> CreateWebViewAsync(this WebViewControlProcess process, Visual visual)
        {
            double width;
            double height;

            if (!visual.Dispatcher.CheckAccess())
            {
                width  = visual.Dispatcher.Invoke(() => (double)visual.GetValue(FrameworkElement.ActualWidthProperty));
                height = visual.Dispatcher.Invoke(() => (double)visual.GetValue(FrameworkElement.ActualHeightProperty));
            }
            else
            {
                width  = (double)visual.GetValue(FrameworkElement.ActualWidthProperty);
                height = (double)visual.GetValue(FrameworkElement.ActualHeightProperty);
            }

            return(process.CreateWebViewAsync(visual, new Rect(new Size(height, width))));
        }
Beispiel #2
0
 /// <summary>
 /// Creates a <see cref="IWebView"/> within the context of <paramref name="process"/> using the <paramref name="visual"/> to create a HWND.
 /// </summary>
 /// <param name="process">An instance of <see cref="WebViewControlProcess" />.</param>
 /// <param name="visual">A <see cref="Visual"/> instance in which to create a HWND.</param>
 /// <returns>An <see cref="IWebView"/> instance.</returns>
 /// <remarks>
 /// The bounds to draw the <see cref="WebView"/> are determined by the height and width of the <paramref name="visual"/>.
 /// </remarks>
 /// <seealso cref="CreateWebViewAsync(WebViewControlProcess,IntPtr,Rect)"/>
 internal static IWebView CreateWebView(this WebViewControlProcess process, Visual visual)
 {
     return(visual.Dispatcher.Invoke(() => process.CreateWebViewAsync(visual).GetAwaiter().GetResult()));
 }