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 · 1 comment
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

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

2 participants