MicrosoftEdge / WebView2Feedback

Feedback and discussions about Microsoft Edge WebView2
https://aka.ms/webview2
450 stars 55 forks source link

When using Webview2 in WPF, unable to overlay WPF controls on the Webview #286

Open ChrisPulman opened 4 years ago

ChrisPulman commented 4 years ago

Webview2 is topmost and any WPF controls are hidden behind the webview2 component. Tried setting the Z index without any success. Should be able to set visibility level by the position in the XAML tree

AB#27046547

benyuz commented 11 months ago

 已收到您的邮件,我会及时查看的!

zhuhaichao518 commented 11 months ago

@ccifra I had finished the implementation,the PR is under review. It seems you have found the same solution. That is great. :) We do not actually need things like a SendKeyboardEvent api to achieve that. You can set focus to the controller and the keyboard events will be sent internally to the browser.

R0315 commented 11 months ago

Hello all!

I have a WPF/blazor hybrid app where I am using a BlazorWebView control to render a component on a WPF ContentControl within the MainWindow. This MainWindow has a hamburger menu intended to float on top and expand to the right over top of the ContentControl. The menu is set to Panel.Zindex 2 with the ContentControl at 1. So, when a user expands the menu, it should expand to the right over top of the rendered page in the ContentControl.

This behavior is working as expected on all pages of my application except for when the BlazorWebView is rendered. It renders as topmost seemingly no matter what I do. I'm new to making a WPF Blazor hybrid application, but I suspect the difference between a BlazorWebView and a WebView2 matters such that @ChrisPulman 's solution may not work in my application (willing to test).

I just wanted to report this same problem for BlazorWebView controls to be sure they are also considered when implementing a solution.

patrickklaeren commented 10 months ago

+1 this is a very useful feature.

We have a pinned/unpinned floating hamburger menu and trying to modernise WPF aspects. The floating hamburger menu does not appear over the top of the browser, no matter the XAML structure.

Memoyu commented 10 months ago

follow

iXab3r commented 8 months ago

@ccifra I had finished the implementation,the PR is under review. It seems you have found the same solution. That is great. :) We do not actually need things like a SendKeyboardEvent api to achieve that. You can set focus to the controller and the keyboard events will be sent internally to the browser.

any luck with PR?

benyuz commented 8 months ago

 已收到您的邮件,我会及时查看的!

zhuhaichao518 commented 8 months ago

It still need some time. We have built a nuget package with the new control for test, contact us in the email thread if you want to try under .NET 462+.

Dmitry Farafonov @.***> 于2024年2月7日周三 20:32写道:

@ccifra https://github.com/ccifra I had finished the implementation,the PR is under review. It seems you have found the same solution. That is great. :) We do not actually need things like a SendKeyboardEvent api to achieve that. You can set focus to the controller and the keyboard events will be sent internally to the browser.

any luck with PR?

— Reply to this email directly, view it on GitHub https://github.com/MicrosoftEdge/WebView2Feedback/issues/286#issuecomment-1931951438 or unsubscribe https://github.com/notifications/unsubscribe-auth/AM4EALHXPORCQO7IDJGXC63YSNX5BBFKMF2HI4TJMJ2XIZLTSWBKK5TBNR2WLJDUOJ2WLJDOMFWWLO3UNBZGKYLEL5YGC4TUNFRWS4DBNZ2F6YLDORUXM2LUPGBKK5TBNR2WLJDUOJ2WLJDOMFWWLLTXMF2GG2C7MFRXI2LWNF2HTAVFOZQWY5LFUVUXG43VMWSG4YLNMWVXI2DSMVQWIX3UPFYGLAVFOZQWY5LFVIYTGNBRGM2DANZSGWSG4YLNMWUWQYLTL5WGCYTFNSBKK5TBNR2WLKRSGM2DEMJQGI4TGMNENZQW2ZNJNBQXGX3MMFRGK3FMON2WE2TFMN2F65DZOBS2YSLTON2WKQ3PNVWWK3TUUZ2G64DJMNZZJAVEOR4XAZNKOJSXA33TNF2G64TZUV3GC3DVMWUTCOBTG4YTIMZYHGBKI5DZOBS2K2LTON2WLJLWMFWHKZNJGYZTSOJZGMZDGNECUR2HS4DFUVWGCYTFNSSXMYLMOVS2UMJTGQYTGNBQG4ZDLAVEOR4XAZNFNRQWEZLMUV3GC3DVMWVDEMZUGIYTAMRZGMY2O5DSNFTWOZLSUZRXEZLBORSQ . You are receiving this email because you commented on the thread.

Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub .

schandra09net commented 8 months ago

Hi Team,

I am interested to the try the control with the new NuGet package, please send me email with the resource.

Thanks & Regards SChandra.

On Fri, 9 Feb 2024 at 03:12, zhuhaichao518 @.***> wrote:

It still need some time. We have built a nuget package with the new control for test, contact us in the email thread if you want to try under .NET 462+.

Dmitry Farafonov @.***> 于2024年2月7日周三 20:32写道:

@ccifra https://github.com/ccifra I had finished the implementation,the PR is under review. It seems you have found the same solution. That is great. :) We do not actually need things like a SendKeyboardEvent api to achieve that. You can set focus to the controller and the keyboard events will be sent internally to the browser.

any luck with PR?

— Reply to this email directly, view it on GitHub < https://github.com/MicrosoftEdge/WebView2Feedback/issues/286#issuecomment-1931951438>

or unsubscribe < https://github.com/notifications/unsubscribe-auth/AM4EALHXPORCQO7IDJGXC63YSNX5BBFKMF2HI4TJMJ2XIZLTSWBKK5TBNR2WLJDUOJ2WLJDOMFWWLO3UNBZGKYLEL5YGC4TUNFRWS4DBNZ2F6YLDORUXM2LUPGBKK5TBNR2WLJDUOJ2WLJDOMFWWLLTXMF2GG2C7MFRXI2LWNF2HTAVFOZQWY5LFUVUXG43VMWSG4YLNMWVXI2DSMVQWIX3UPFYGLAVFOZQWY5LFVIYTGNBRGM2DANZSGWSG4YLNMWUWQYLTL5WGCYTFNSBKK5TBNR2WLKRSGM2DEMJQGI4TGMNENZQW2ZNJNBQXGX3MMFRGK3FMON2WE2TFMN2F65DZOBS2YSLTON2WKQ3PNVWWK3TUUZ2G64DJMNZZJAVEOR4XAZNKOJSXA33TNF2G64TZUV3GC3DVMWUTCOBTG4YTIMZYHGBKI5DZOBS2K2LTON2WLJLWMFWHKZNJGYZTSOJZGMZDGNECUR2HS4DFUVWGCYTFNSSXMYLMOVS2UMJTGQYTGNBQG4ZDLAVEOR4XAZNFNRQWEZLMUV3GC3DVMWVDEMZUGIYTAMRZGMY2O5DSNFTWOZLSUZRXEZLBORSQ>

. You are receiving this email because you commented on the thread.

Triage notifications on the go with GitHub Mobile for iOS < https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>

or Android < https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>

.

— Reply to this email directly, view it on GitHub https://github.com/MicrosoftEdge/WebView2Feedback/issues/286#issuecomment-1934979067, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMOSOE5KTTJKTU5JMWDSCC3YSVBFTAVCNFSM4OAAJS52U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOJTGQ4TOOJQGY3Q . You are receiving this because you were mentioned.Message ID: @.***>

zhuhaichao518 commented 8 months ago

Here is a sample code of using the new control with a nuget package for test. wv2-wpf-composition-control.zip In order to use it, extract the zip and can put 'nuget' folder in it into root of C:/ (you can modify it in NuGet.Config), and then run solution in WebView2WpfBrowserTest(modified from our github sample:https://github.com/MicrosoftEdge/WebView2Samples/tree/main/SampleApps/WebView2WpfBrowser) , modified from our sample app by replacing the WebView2 control with WebView2CompositionControl. That build was not including dpi awareness support and .NET 6+ support. You can try if it can satisfy your requirement. Thanks! @schandra09net @iXab3r

schandra09net commented 8 months ago

Here is a sample code of using the new control with a nuget package for test. wv2-wpf-composition-control.zip In order to use it, extract the zip and can put 'nuget' folder in it into root of C:/ (you can modify it in NuGet.Config), and then run solution in WebView2WpfBrowserTest(modified from our github sample:https://github.com/MicrosoftEdge/WebView2Samples/tree/main/SampleApps/WebView2WpfBrowser) , modified from our sample app by replacing the WebView2 control with WebView2CompositionControl. That build was not including dpi awareness support and .NET 6+ support. You can try if it can satisfy your requirement. Thanks! @schandra09net @iXab3r

Thanks for providing this. will try to add this to my project and will update this thread accordingly. 👍

schandra09net commented 8 months ago

Hello @zhuhaichao518,

I have tested with the new control and facing an issue, please check and can you provide the solution/suggestion accordingly?

Issue: System.InvalidOperationException: An attempt was made to transition a task to a final state when it had already completed.

Steps to reproduce:

  1. Create a WPF application with .NET v4.6.2 framework
  2. Place the "Microsoft.Web.WebView2.1.0.2274.nupkg" in c:\nuget and add the NuGet reference to the above project.
  3. Add two XAML files "MainWindow" and "WebView2Browser" as below.

MainWindows.xaml

<Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <ContentControl x:Name="LeftGridContent" Grid.Column="0">
            <local:WebView2Browser Canvas.Left="2" Canvas.Top="1" SourceAddress="https://www.bbc.com"  />
        </ContentControl>
        <ContentControl x:Name="RightGridContent" Grid.Column="1">
            <local:WebView2Browser Canvas.Left="2" Canvas.Top="1" SourceAddress="https://www.google.com"/>
        </ContentControl>
        <Button x:Name="SwapCotntent" Click="SwapCotntent_Click" Content="Swap" Grid.Column="2" Width="100" Height="30"/>
    </Grid>

MainWindows.xaml.cs

private void SwapCotntent_Click(object sender, RoutedEventArgs e)
        {    
            try
            {
                var righGridContent= RightGridContent.Content; ;
                var leftGridContent = LeftGridContent.Content; ;
                Dispatcher.Invoke(() =>
                {
                    LeftGridContent.Content=righGridContent;
                    RightGridContent.Content=leftGridContent;
                });
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.StackTrace);
            }

            e.Handled=true;
        }

WebView2Browser.xaml

<UserControl x:Class="WebViewComposition.WebView2Browser"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:local="clr-namespace:Microsoft.Web.WebView2.Wpf;assembly=Microsoft.Web.WebView2.Wpf"
             mc:Ignorable="d">
    <Grid>       
        <local:WebView2CompositionControl x:Name="webView"/>
        <Button x:Name="overlayButton" Width="150" Height="35" Content="Sketch on WebViewComposition"
                HorizontalAlignment="Left" PreviewMouseDoubleClick="overlayButton_PreviewMouseDoubleClick" 
                Background="Transparent" Foreground="#AE0190"
                FontWeight="Bold" FontSize="12" />       
    </Grid>    
</UserControl>

WebView2Browser.xaml.cs:

public partial class WebView2Browser : UserControl
    {
        public string SourceAddress
        {
            get { return (string)GetValue(TextDependecseProperty); }
            set { SetValue(TextDependecseProperty, value); }
        }

        public static readonly DependencyProperty TextDependecseProperty =
            DependencyProperty.Register(@"SourceAddress", typeof(string), typeof(WebView2Browser), new PropertyMetadata(String.Empty));

        public WebView2Browser()
        {
            InitializeComponent();

            InitializeWeb();
        }

        async void InitializeWeb()
        {
            await webView.EnsureCoreWebView2Async();
            webView.Source=new Uri(SourceAddress);

            var str = SourceAddress.Split('.')[1];
            overlayButton.Content="Draw on: "+ char.ToUpper(str[0]) + str.Substring(1);
        }

        private void overlayButton_PreviewMouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            MessageBox.Show("Sketch now on: "+SourceAddress);
        }
    }

Exception StackTrace:

System.InvalidOperationException
  HResult=0x80131509
  Message=An attempt was made to transition a task to a final state when it had already completed.
  Source=mscorlib
  StackTrace:
   at System.Threading.Tasks.TaskCompletionSource`1.SetResult(TResult result)
   at Microsoft.Web.WebView2.Wpf.WebView2CompositionControl.WebView2CompositionControl_Loaded(Object sender, RoutedEventArgs e)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at System.Windows.BroadcastEventHelper.BroadcastEvent(DependencyObject root, RoutedEvent routedEvent)
   at System.Windows.BroadcastEventHelper.BroadcastLoadedEvent(Object root)
   at MS.Internal.LoadedOrUnloadedOperation.DoWork()
   at System.Windows.Media.MediaContext.FireLoadedPendingCallbacks()
   at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
   at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
   at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.DispatcherOperation.InvokeImpl()
   at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(Object obj)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Windows.Threading.DispatcherOperation.Invoke()
   at System.Windows.Threading.Dispatcher.ProcessQueue()
   at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
   at System.Windows.Application.RunDispatcher(Object ignore)
   at System.Windows.Application.RunInternal(Window window)
   at WebViewComposition.App.Main()

UI for reference: image

Video for reference: https://github.com/MicrosoftEdge/WebView2Feedback/assets/52242195/8818f407-81dc-41b8-8fbf-0799af5dd168

Can you suggest how to fix this, or is this a known issue?

CocoDico78 commented 8 months ago

It still need some time. We have built a nuget package with the new control for test, contact us in the email thread if you want to try under .NET 462+.

Is there any plans of releasing this to .NET Core?

schandra09net commented 8 months ago

Hello @zhuhaichao518,

I have tested with the new control and facing an issue, please check and can you provide the solution/suggestion accordingly?

Issue: System.InvalidOperationException: An attempt was made to transition a task to a final state when it had already completed.

Steps to reproduce:

  1. Create a WPF application with .NET v4.6.2 framework
  2. Place the "Microsoft.Web.WebView2.1.0.2274.nupkg" in c:\nuget and add the NuGet reference to the above project.
  3. Add two XAML files "MainWindow" and "WebView2Browser" as below.

MainWindows.xaml

<Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <ContentControl x:Name="LeftGridContent" Grid.Column="0">
            <local:WebView2Browser Canvas.Left="2" Canvas.Top="1" SourceAddress="https://www.bbc.com"  />
        </ContentControl>
        <ContentControl x:Name="RightGridContent" Grid.Column="1">
            <local:WebView2Browser Canvas.Left="2" Canvas.Top="1" SourceAddress="https://www.google.com"/>
        </ContentControl>
        <Button x:Name="SwapCotntent" Click="SwapCotntent_Click" Content="Swap" Grid.Column="2" Width="100" Height="30"/>
    </Grid>

MainWindows.xaml.cs

private void SwapCotntent_Click(object sender, RoutedEventArgs e)
        {    
            try
            {
                var righGridContent= RightGridContent.Content; ;
                var leftGridContent = LeftGridContent.Content; ;
                Dispatcher.Invoke(() =>
                {
                    LeftGridContent.Content=righGridContent;
                    RightGridContent.Content=leftGridContent;
                });
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.StackTrace);
            }

            e.Handled=true;
        }

WebView2Browser.xaml

<UserControl x:Class="WebViewComposition.WebView2Browser"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:local="clr-namespace:Microsoft.Web.WebView2.Wpf;assembly=Microsoft.Web.WebView2.Wpf"
             mc:Ignorable="d">
    <Grid>       
        <local:WebView2CompositionControl x:Name="webView"/>
        <Button x:Name="overlayButton" Width="150" Height="35" Content="Sketch on WebViewComposition"
                HorizontalAlignment="Left" PreviewMouseDoubleClick="overlayButton_PreviewMouseDoubleClick" 
                Background="Transparent" Foreground="#AE0190"
                FontWeight="Bold" FontSize="12" />       
    </Grid>    
</UserControl>

WebView2Browser.xaml.cs:

public partial class WebView2Browser : UserControl
    {
        public string SourceAddress
        {
            get { return (string)GetValue(TextDependecseProperty); }
            set { SetValue(TextDependecseProperty, value); }
        }

        public static readonly DependencyProperty TextDependecseProperty =
            DependencyProperty.Register(@"SourceAddress", typeof(string), typeof(WebView2Browser), new PropertyMetadata(String.Empty));

        public WebView2Browser()
        {
            InitializeComponent();

            InitializeWeb();
        }

        async void InitializeWeb()
        {
            await webView.EnsureCoreWebView2Async();
            webView.Source=new Uri(SourceAddress);

            var str = SourceAddress.Split('.')[1];
            overlayButton.Content="Draw on: "+ char.ToUpper(str[0]) + str.Substring(1);
        }

        private void overlayButton_PreviewMouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            MessageBox.Show("Sketch now on: "+SourceAddress);
        }
    }

Exception StackTrace:

System.InvalidOperationException
  HResult=0x80131509
  Message=An attempt was made to transition a task to a final state when it had already completed.
  Source=mscorlib
  StackTrace:
   at System.Threading.Tasks.TaskCompletionSource`1.SetResult(TResult result)
   at Microsoft.Web.WebView2.Wpf.WebView2CompositionControl.WebView2CompositionControl_Loaded(Object sender, RoutedEventArgs e)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at System.Windows.BroadcastEventHelper.BroadcastEvent(DependencyObject root, RoutedEvent routedEvent)
   at System.Windows.BroadcastEventHelper.BroadcastLoadedEvent(Object root)
   at MS.Internal.LoadedOrUnloadedOperation.DoWork()
   at System.Windows.Media.MediaContext.FireLoadedPendingCallbacks()
   at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
   at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
   at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.DispatcherOperation.InvokeImpl()
   at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(Object obj)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Windows.Threading.DispatcherOperation.Invoke()
   at System.Windows.Threading.Dispatcher.ProcessQueue()
   at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
   at System.Windows.Application.RunDispatcher(Object ignore)
   at System.Windows.Application.RunInternal(Window window)
   at WebViewComposition.App.Main()

UI for reference: image

Video for reference: https://github.com/MicrosoftEdge/WebView2Feedback/assets/52242195/8818f407-81dc-41b8-8fbf-0799af5dd168

Can you suggest how to fix this, or is this a known issue?

Hi @zhuhaichao518,

Found this issue https://github.com/MicrosoftEdge/WebView2Feedback/issues/382 which was created on the earlier verison of WebView2, and seems like that was fixed.

This might be the same issue with the current NuGet package that you provided, I thought the above ticket might provide you some insights.

Looking forward to your update on the possible fix.

Thanks

schandra09net commented 8 months ago

Here is a sample code of using the new control with a nuget package for test. wv2-wpf-composition-control.zip In order to use it, extract the zip and can put 'nuget' folder in it into root of C:/ (you can modify it in NuGet.Config), and then run solution in WebView2WpfBrowserTest(modified from our github sample:https://github.com/MicrosoftEdge/WebView2Samples/tree/main/SampleApps/WebView2WpfBrowser) , modified from our sample app by replacing the WebView2 control with WebView2CompositionControl. That build was not including dpi awareness support and .NET 6+ support. You can try if it can satisfy your requirement. Thanks! @schandra09net @iXab3r

Hi @zhuhaichao518 and @ChrisPulman,

In extension to my comment above, I tried analyzing the WebView2CompositionControl_Loaded method, and below are my observations:

  1. Microsoft.Web.WebView2.Wpf.WebView2CompositionControl.WebView2CompositionControl_Loaded(Object sender, RoutedEventArgs e) assumes the control will be loaded only once, but as in my POC, when I assign the ContentControl.Content, WebView2CompositionControl Loaded method is re-initializing and throwing the exception.
 private void WebView2CompositionControl_Loaded(object sender, RoutedEventArgs e)
 {
     //IL_001d: Unknown result type (might be due to invalid IL or missing references)
     //IL_0027: Expected O, but got Unknown
     if (!IsInDesignMode)
     {
         dispatcherQueue = InitializeCoreDispatcher();
         compositor = new Compositor();
         wincompWebViewVisual = compositor.CreateContainerVisual();
         Window.GetWindow(this).LocationChanged += WebView2CompositionControl_LocationChanged;
         IntPtr handle = new WindowInteropHelper(Window.GetWindow(this)).Handle;
         d3dimage = new GraphicsItemD3DImage(handle, image);
         d3dimage.ApplyCompositor(wincompWebViewVisual, hostWidth, hostHeight);
         **__hwndTaskSource.SetResult(handle); // THIS LINE THROWS EXCEPTION_**
     }
 }

Ask: Can you make the re-load of the WebView2CompositionControl to handle the re-initialization smoothly?

  1. Touch events are completely not working (TouchDown, TouchMove, TouchUp) on the control with any webpage. So scrolling on the Page with a touch gesture is "Selecting the text in the webpage" instead of "scrolling the webpage". But I see no issue with the mouse scroll event, which is scrolling as expected.

Seems like Touch events are not implemented for the WebView2CompositionControl yet, is my understanding true?

In the code, it has only MouseInput when I checked it. CoreWebView2CompositionController.SendMouseInput(eventKind, mouseEventVirtualKeys, 0u, mouselocation);

Ask: Can you provide the WebView2CompositionControl NuGet package or sample app that has touch events support?

zhuhaichao518 commented 8 months ago

@schandra09net Hi, I have added code to avoid initializing more than once and added some basic support for touch event. Microsoft.Web.WebView2.1.0.2418.zip

schandra09net commented 8 months ago

@schandra09net Hi, I have added code to avoid initializing more than once and added some basic support for touch event. Microsoft.Web.WebView2.1.0.2418.zip

Hi @zhuhaichao518,

Thanks for updating the changes and providing the latest zip, will check and let you know.

thirking commented 8 months ago

Exciting new feature! I look forward to its release as soon as possible.

Amine-Smahi commented 8 months ago

Hi, from 2024 😉

Is there any updates ?

patrickklaeren commented 8 months ago

Hi, from 2024 😉

Is there any updates ?

I think the comments in this thread above have the updates you're looking for.

schandra09net commented 8 months ago

@schandra09net Hi, I have added code to avoid initializing more than once and added some basic support for touch events. Microsoft.Web.WebView2.1.0.2418.zip

Hi @zhuhaichao518,

Thanks for updating the changes and providing the latest zip, will check and let you know.

Hi @zhuhaichao518 and @ChrisPulman

I have tested the latest NuGet provided:

  1. Now, not getting any exceptions on reload of the control (WebView2CompositionControl_Loaded), and it is completely working.✅
  2. Touch scroll is working as expected. ✅

Thanks for updating.

But two questions:

  1. Created a simple WPF application with a WebView2CompositionControl inside a grid, running with any system resolution, for example, set to 1920x1080 and scaling to 100%, seeing no issues with touch. But modifying scaling other than 100% let's say 125% or any higher value, touch events are not exactly clicking the elements where they are touched, missing some offset points.

Ask: Can you let me know if the control is DPIAware, if not can you provide me the NuGet to test that has DPI scaling?

  1. PreviewTouch events(PreviewTouchDown, PreviewTouchMove, PreviewTouchUp) are getting fired (in debug mode), but Touch events(TouchDown, TouchMove, and TouchUp) are not triggered on this control.

Ask: Can you let me know if this is a known issue, or if implementation is in progress? If not can you provide me the NuGet with touch bubbling events?

Looking forward to your updates.

Thanks.

zhuhaichao518 commented 7 months ago

@schandra09net Hi, I have added code to avoid initializing more than once and added some basic support for touch events. Microsoft.Web.WebView2.1.0.2418.zip

Hi @zhuhaichao518, Thanks for updating the changes and providing the latest zip, will check and let you know.

Hi @zhuhaichao518 and @ChrisPulman

I have tested the latest NuGet provided:

  1. Now, not getting any exceptions on reload of the control (WebView2CompositionControl_Loaded), and it is completely working.✅
  2. Touch scroll is working as expected. ✅

Thanks for updating.

But two questions:

  1. Created a simple WPF application with a WebView2CompositionControl inside a grid, running with any system resolution, for example, set to 1920x1080 and scaling to 100%, seeing no issues with touch. But modifying scaling other than 100% let's say 125% or any higher value, touch events are not exactly clicking the elements where they are touched, missing some offset points.

Ask: Can you let me know if the control is DPIAware, if not can you provide me the NuGet to test that has DPI scaling?

  1. PreviewTouch events(PreviewTouchDown, PreviewTouchMove, PreviewTouchUp) are getting fired (in debug mode), but Touch events(TouchDown, TouchMove, and TouchUp) are not triggered on this control.

Ask: Can you let me know if this is a known issue, or if implementation is in progress? If not can you provide me the NuGet with touch bubbling events?

Looking forward to your updates.

Thanks.

Hi, Thanks a lot for point out the issue. This control requires a refactor of our whole WPF control framework, and it costs much time.

Here is my answer:

I am unable to carry out every fix and update to the package here. You are welcome to test the issues with the provided package, and there is a promise for them to be fixed in the release version.

schandra09net commented 7 months ago

@schandra09net Hi, I have added code to avoid initializing more than once and added some basic support for touch events. Microsoft.Web.WebView2.1.0.2418.zip

Hi @zhuhaichao518, Thanks for updating the changes and providing the latest zip, will check and let you know.

Hi @zhuhaichao518 and @ChrisPulman I have tested the latest NuGet provided:

  1. Now, not getting any exceptions on reload of the control (WebView2CompositionControl_Loaded), and it is completely working.✅
  2. Touch scroll is working as expected. ✅

Thanks for updating. But two questions:

  1. Created a simple WPF application with a WebView2CompositionControl inside a grid, running with any system resolution, for example, set to 1920x1080 and scaling to 100%, seeing no issues with touch. But modifying scaling other than 100% let's say 125% or any higher value, touch events are not exactly clicking the elements where they are touched, missing some offset points.

Ask: Can you let me know if the control is DPIAware, if not can you provide me the NuGet to test that has DPI scaling?

  1. PreviewTouch events(PreviewTouchDown, PreviewTouchMove, PreviewTouchUp) are getting fired (in debug mode), but Touch events(TouchDown, TouchMove, and TouchUp) are not triggered on this control.

Ask: Can you let me know if this is a known issue, or if implementation is in progress? If not can you provide me the NuGet with touch bubbling events?

Looking forward to your updates. Thanks.

Hi, Thanks a lot for point out the issue. This control requires a refactor of our whole WPF control framework, and it costs much time.

Here is my answer:

  • The dpi awareness is a known issue, which requires carefully design. The WPF framework has different scale models which is not sync with browser. I did not include it in the package.
  • The touch events were just added as you required. I haven't tested it a lot. :)

I am unable to carry out every fix and update to the package here. You are welcome to test the issues with the provided package, and there is a promise for them to be fixed in the release version.

Hi @zhuhaichao518 ,

Thanks for your response, for now, the package provided covers 80% of issues compared to CefSharp which I was using earlier.

In future releases excepting these issues covered, that will be a perfect choice to use an embedded browser for the WPF application.

Waiting for it soon.

mafei1982 commented 7 months ago

@zhuhaichao518 I saw there is pre release 1.0.2470-prerelease, does this release include the fix?

zhuhaichao518 commented 7 months ago

Not yet. I will notify you when the new control is released. Thanks!

mafei1982 @.***>于2024年3月27日 周三17:44写道:

@zhuhaichao518 https://github.com/zhuhaichao518 I saw there is pre release 1.0.2470-prerelease https://www.nuget.org/packages/Microsoft.Web.WebView2/1.0.2470-prerelease, does this release include the fix?

— Reply to this email directly, view it on GitHub https://github.com/MicrosoftEdge/WebView2Feedback/issues/286#issuecomment-2022329170 or unsubscribe https://github.com/notifications/unsubscribe-auth/AM4EALCBQRMDBAGIQOJMKP3Y2KIHFBFKMF2HI4TJMJ2XIZLTSWBKK5TBNR2WLJDUOJ2WLJDOMFWWLO3UNBZGKYLEL5YGC4TUNFRWS4DBNZ2F6YLDORUXM2LUPGBKK5TBNR2WLJDUOJ2WLJDOMFWWLLTXMF2GG2C7MFRXI2LWNF2HTAVFOZQWY5LFUVUXG43VMWSG4YLNMWVXI2DSMVQWIX3UPFYGLAVFOZQWY5LFVIYTGNBRGM2DANZSGWSG4YLNMWUWQYLTL5WGCYTFNSBKK5TBNR2WLKRSGM2DEMJQGI4TGMNENZQW2ZNJNBQXGX3MMFRGK3FMON2WE2TFMN2F65DZOBS2YSLTON2WKQ3PNVWWK3TUUZ2G64DJMNZZJAVEOR4XAZNKOJSXA33TNF2G64TZUV3GC3DVMWUTCOBTG4YTIMZYHGBKI5DZOBS2K2LTON2WLJLWMFWHKZNJGYZTSOJZGMZDGNECUR2HS4DFUVWGCYTFNSSXMYLMOVS2UMJTGQYTGNBQG4ZDLAVEOR4XAZNFNRQWEZLMUV3GC3DVMWVDEMZUGIYTAMRZGMY2O5DSNFTWOZLSUZRXEZLBORSQ . You are receiving this email because you were mentioned.

Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub .

mafei1982 commented 7 months ago

Not yet. I will notify you when the new control is released. Thanks! mafei1982 @.***>于2024年3月27日 周三17:44写道: @zhuhaichao518 https://github.com/zhuhaichao518 I saw there is pre release 1.0.2470-prerelease https://www.nuget.org/packages/Microsoft.Web.WebView2/1.0.2470-prerelease, does this release include the fix? — Reply to this email directly, view it on GitHub <#286 (comment)> or unsubscribe https://github.com/notifications/unsubscribe-auth/AM4EALCBQRMDBAGIQOJMKP3Y2KIHFBFKMF2HI4TJMJ2XIZLTSWBKK5TBNR2WLJDUOJ2WLJDOMFWWLO3UNBZGKYLEL5YGC4TUNFRWS4DBNZ2F6YLDORUXM2LUPGBKK5TBNR2WLJDUOJ2WLJDOMFWWLLTXMF2GG2C7MFRXI2LWNF2HTAVFOZQWY5LFUVUXG43VMWSG4YLNMWVXI2DSMVQWIX3UPFYGLAVFOZQWY5LFVIYTGNBRGM2DANZSGWSG4YLNMWUWQYLTL5WGCYTFNSBKK5TBNR2WLKRSGM2DEMJQGI4TGMNENZQW2ZNJNBQXGX3MMFRGK3FMON2WE2TFMN2F65DZOBS2YSLTON2WKQ3PNVWWK3TUUZ2G64DJMNZZJAVEOR4XAZNKOJSXA33TNF2G64TZUV3GC3DVMWUTCOBTG4YTIMZYHGBKI5DZOBS2K2LTON2WLJLWMFWHKZNJGYZTSOJZGMZDGNECUR2HS4DFUVWGCYTFNSSXMYLMOVS2UMJTGQYTGNBQG4ZDLAVEOR4XAZNFNRQWEZLMUV3GC3DVMWVDEMZUGIYTAMRZGMY2O5DSNFTWOZLSUZRXEZLBORSQ . You are receiving this email because you were mentioned. Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub .

Is there a plan about when it could be released?

vesamaunula commented 6 months ago

Also like to get this asap...

ITILD commented 5 months ago

can this issue fixed Transparent pages and clickthrough/mouse/keyboard events

benyuz commented 5 months ago

 已收到您的邮件,我会及时查看的!

zhuhaichao518 commented 4 months ago

@vesamaunula @mafei1982 @schandra09net @Amine-Smahi @patrickklaeren Hi, I expect the WebView2CompositionControl implementation inside the pre-release package following edge 127 release, which is around the end of July/Start of August. Thanks!

benyuz commented 4 months ago

 已收到您的邮件,我会及时查看的!

schandra09net commented 3 months ago

@vesamaunula @mafei1982 @schandra09net @Amine-Smahi @patrickklaeren Hi, I expect the WebView2CompositionControl implementation inside the pre-release package following edge 127 release, which is around the end of July/Start of August. Thanks!

Hello @zhuhaichao518 and @ChrisPulman,

Can you let us know the latest status update on this, is it in line with the timeline specified?

benyuz commented 3 months ago

 已收到您的邮件,我会及时查看的!

ChrisPulman commented 3 months ago

I have recently updated CrissCross.WPF.WebView2 to fix some of the findings users have notified. You're welcome to use CrissCross in the meantime, it solves some of the problems with overlaying Wpf controls but not all.

@zhuhaichao518 FYI It has been noted that on Windows 10 there is a border generated around the webview2 component that does not exist on Windows 11

zhuhaichao518 commented 2 months ago

@vesamaunula @mafei1982 @schandra09net @Amine-Smahi @patrickklaeren Hi, I expect the WebView2CompositionControl implementation inside the pre-release package following edge 127 release, which is around the end of July/Start of August. Thanks!

Hello @zhuhaichao518 and @ChrisPulman,

Can you let us know the latest status update on this, is it in line with the timeline specified?

Hi, currently it is in 1.0.2646-prerelease WebView2CompositionControl Class (Microsoft.Web.WebView2.Wpf) | Microsoft Learn and you can use it exactly like how WebView2 control is used. I expect your feedback about the new control and promote to stable when appropriate. Thanks!

mr-luiks commented 2 months ago

Hi, currently it is in 1.0.2646-prerelease WebView2CompositionControl Class (Microsoft.Web.WebView2.Wpf) | Microsoft Learn and you can use it exactly like how WebView2 control is used. I expect your feedback about the new control and promote to stable when appropriate. Thanks!

will it be available for net core? as it right now it only works with net framework.

ChrisPulman commented 2 months ago

Hi, currently it is in 1.0.2646-prerelease WebView2CompositionControl Class (Microsoft.Web.WebView2.Wpf) | Microsoft Learn and you can use it exactly like how WebView2 control is used. I expect your feedback about the new control and promote to stable when appropriate. Thanks!

will it be available for net core?

You can use this control for both Net Framework and Net Core

cmiles commented 2 months ago

Is this .NET 9 only? I just gave it a quick try in a .NET Core 8 project of mine and received a Platform Not Supported Exception - seemed worth asking before doing any other troubleshooting...

System.PlatformNotSupportedException: Operation is not supported on this platform. (0x80131539) at Microsoft.Web.WebView2.Wpf.WebView2CompositionControl.WebView2CompositionControl_Loaded(Object sender, RoutedEventArgs e) at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised) at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args) at System.Windows.BroadcastEventHelper.BroadcastEvent(DependencyObject root, RoutedEvent routedEvent) at System.Windows.BroadcastEventHelper.BroadcastLoadedEvent(Object root) at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks() at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget) at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)

mr-luiks commented 2 months ago

You can use this control for both Net Framework and Net Core

on .net 8 it gives me error "Operation is not supported on this platform. (0x80131539)" while on .net framework 4.8.1 works fine.

ChrisPulman commented 2 months ago

image I have noted that with this Pre Release you will need to include the package in your end application otherwise the Webview2 is not found, otherwise it seems to work without issue.

The Error without the package included: error MC1000: Unknown build error, 'Could not find assembly 'Microsoft.Web.WebView2.Wpf, Version=1.0.2646.0, Culture=neutral, PublicKeyToken=2a8ab48044d2601e'. Either explicitly load this assembly using a method such as LoadFromAssemblyPath() or use a MetadataAssemblyResolver that returns a valid assembly.

cmiles commented 2 months ago

@ChrisPulman Thanks for the information, useful to see it working and your project settings - fwiw including the package directly in the end application didn't change the Platform not Supported exception for me. I'll have to put together a smaller test solution at some point to see what the key difference is...

zhuhaichao518 commented 2 months ago

@cmiles @mr-luiks Unfortunately we have not added support for .NET 5.0+ yet. Would you please fire a bug for this? Add support for .NET 5.0+ requires some additional work.

ChrisPulman commented 2 months ago

Hi, currently it is in 1.0.2646-prerelease WebView2CompositionControl Class (Microsoft.Web.WebView2.Wpf) | Microsoft Learn and you can use it exactly like how WebView2 control is used. I expect your feedback about the new control and promote to stable when appropriate. Thanks!

will it be available for net core?

You can use this control for both Net Framework and Net Core

Sorry, I was using the WebView2 component directly not the Microsoft.Web.WebView2.Wpf.WebView2CompositionControl, sorry for misleading you.

cmiles commented 2 months ago

@zhuhaichao518 I created #4726 - if there are additional details needed or a better way to do this please let me know.

simon1689 commented 2 months ago

When can we expect a stable version and will it include NET 8 support?

ProgrammerLP commented 2 months ago

we need .net 8 (core) Support

CocoDico78 commented 2 months ago

@cmiles @mr-luiks Unfortunately we have not added support for .NET 5.0+ yet. Would you please fire a bug for this? Add support for .NET 5.0+ requires some additional work.

Absolutely need .NET 8/9 + whatever is coming after. Our team luckily moved away from .NET Framework long ago.

champnic commented 2 months ago

We're working on adding .NET 5+ support as we speak. It's going through testing and hopefully will be available to test in the upcoming prerelease SDK.

philiphendry commented 2 months ago

I upgraded to version 1.0.2651.64 but the WebView2CompositionControl is internal whilst in the previous 1.0.2646-prerelease it was public and solved my problems . I've also tried upgrading to the very latest 1.0.2730-prerelease and that also works. Is there a plan to make WebView2CompositionControl public in a stable release?

champnic commented 2 months ago

@philiphendry Yes we are working to make it public in a stable release. We need to add support for .NET 5+ first and add some more testing. Please let us know if you run into any problems when you try it out using the prerelease version!