How to enable horizontal scrolling with mouse?

后端 未结 6 1896
旧巷少年郎
旧巷少年郎 2021-02-01 07:54

I cannot determine how to scroll horizontally using the mouse wheel. Vertical scrolling works well automatically, but I need to scroll my content horizontally. My code looks lik

6条回答
  •  滥情空心
    2021-02-01 08:44

    I was kinda looking for the most simple way to make any ScrollViewer scroll left-right instead of up-down. So here is the simplest combination of the other answers.

     
    

    and:

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

    This is basically what John Gardner suggested just with the actual code. I'm also quoting my answer from similar question here.

提交回复
热议问题