shanthosh
shanthosh

Reputation: 25

Shift + Mouse Wheel to scroll horizontally

I just need some help on how to scroll HORIZONTALLY by using (SHIFT + MOUSE SCROLL) IN WPF application.

private void RadGridViewRoomsSummary_MouseWheel_1(object sender, MouseWheelEventArgs e)
{ ScrollViewer scrollViewer = sender as ScrollViewer;
        if (e.Delta > 0)
            scrollViewer.LineLeft();
        else
            scrollViewer.LineRight();
        e.Handled = true;
}

BY using a keyboard "shift + mouse scroll" I want to move a from left to right horizontally by specific windows.

Upvotes: 0

Views: 2759

Answers (1)

redcurry
redcurry

Reputation: 2497

In your ScrollViewer, handle its PreviewMouseWheel event. Here's the handler:

private void OnMouseWheel(object sender, MouseWheelEventArgs e)
{
    var scrollViewer = (ScrollViewer)sender;

    if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift))
    {
        scrollViewer.ScrollToHorizontalOffset(scrollViewer.HorizontalOffset - e.Delta);
        e.Handled = true;
    }
}

Upvotes: 1

Related Questions