Search code examples
wpfinputbinding

WPF InputBinding Ctrl+MWheelUp/Down Possible?


Is there a way I can bind a Command to Ctrl+MWheelUp/Down? U know in a browser, you can do the same to increase/decrease font size? I want to replicate that effect in WPF. Possible? I was looking at InputBinding > MouseBindings and MouseAction does not seem to support Mouse Scrolls.

* I seem to have posted a similar question, but can't find it anymore


Solution

  • Ok, I did something like this in my ShellView : Window

    this.KeyDown += (s, e) =>
    {
        _leftCtrlPressed = (e.Key == Key.LeftCtrl) ? true : false;
    };
    
    this.MouseWheel += (s, e) =>
    {
        if (_leftCtrlPressed) {
            if (e.Delta > 0)
                _vm.Options.FontSize += 1;
            else if (e.Delta < 0)
                _vm.Options.FontSize -= 1;
        }
    };
    

    I think the Behaviour method will make things cleaner and more reusable, but I didn't really get it. It'll will be great if someone explained it in a simple way here?