Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Problem/Bug]: Capture MouseWheel and PreviewMouseWheel events in EdgeWebview2 wpf app #5101

Open
poynting-dev opened this issue Feb 13, 2025 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@poynting-dev
Copy link

What happened?

I am unable to capture and handle MouseWheel and PreviewMouseWheel events in Edge WebView2 WPF app.

I am pressing (Ctrl + Mouse wheel scroll) and c# app is not capturing the events.

Importance

Blocking. My app's basic functions are not working due to this issue.

Runtime Channel

Stable release (WebView2 Runtime)

Runtime Version

133.0.3065.59

SDK Version

1.0.3065.39

Framework

WPF

Operating System

Windows 10

OS Version

10.0.19045.5371

Repro steps

Code to reproduce:

using Microsoft.Web.WebView2.Core;
using System;
using System.Windows;
using System.Windows.Input;

namespace WpfApp
{
    public partial class MainWindow : Window
    {
        private double zoomFactor = 1.0;

        public MainWindow()
        {
            InitializeComponent();
            InitializeWebView();
        }

        private async void InitializeWebView()
        {
            await webView.EnsureCoreWebView2Async(null);
            webView.CoreWebView2.Navigate("https://example.com"); // Replace with your desired URL
        }

        private void Window_MouseWheel(object sender, MouseWheelEventArgs e)
        {
            // Check the direction of the scroll
            if (e.Delta > 0) // Scrolling up
            {
                ZoomIn();
            }
            else // Scrolling down
            {
                ZoomOut();
            }

            // Mark the event as handled to prevent further processing
            e.Handled = true;
        }

        private void ZoomIn()
        {
            zoomFactor += 0.1;
            webView.CoreWebView2.ZoomFactor = zoomFactor;
        }

        private void ZoomOut()
        {
            zoomFactor = Math.Max(0.1, zoomFactor - 0.1); // Prevent zooming out too much
            webView.CoreWebView2.ZoomFactor = zoomFactor;
        }
    }
}

Repros in Edge Browser

No, issue does not reproduce in the corresponding Edge version

Regression

Don't know

Last working version (if regression)

No response

@poynting-dev poynting-dev added the bug Something isn't working label Feb 13, 2025
@poynting-dev
Copy link
Author

@sivMSFT

@ClosetBugSlayer
Copy link

ClosetBugSlayer commented Feb 13, 2025

I don't know if this is related but 133.0.3065.59 intermittently stops accepting mouse scroll wheel input on my machine, and I can't get it back till I right-click and bring up a context menu on the page. The web page itself doesn't even receive the input; it won't scroll. This is also embedded in a WPF app.

@ClosetBugSlayer
Copy link

I don't know if this is related but 133.0.3065.59 intermittently stops accepting mouse scroll wheel input on my machine, and I can't get it back till I right-click and bring up a context menu on the page. The web page itself doesn't even receive the input; it won't scroll. This is also embedded in a WPF app.

Actually it's very simple. I have a mouse with a 4-direction mousewheel touch surface that can submit horizontal scroll input, a Microsoft Explorer Touch mouse that isn't made anymore. When I use the mouse to scroll horizontally (left <--> right), the vertical scrolling in WebView2 stops working even if the webpage doesn't have horizontal scrollbars. Invoking a context menu fixes it, even if I use the right context menu key on the keyboard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants