Skip to content

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

Open
@poynting-dev

Description

@poynting-dev

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions