Activate horizontal scrolling with mouse on ListView

后端 未结 4 1141
不思量自难忘°
不思量自难忘° 2020-12-18 13:30

I\'ve got a custom horizontal ListView with custom ScrollViewer inside it\'s template (created with Blend). I want it to scroll horizontally when using mouse scrolling wheel

4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-18 14:10

    Xaml Code:

     
    
    

    C# Code

    private void ScrollViewer_PreviewMouseWheel(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;
        }
    }
    

提交回复
热议问题