1.在DataGrid中添加PreviewMouseWheel事件,并将事件的Handled属性设置为false,以便将滚动事件传递给ScrollViewer。示例代码如下:
<DataGrid PreviewMouseWheel="DataGrid_PreviewMouseWheel"> <!-- DataGrid的其他设置 --> </DataGrid>
private void DataGrid_PreviewMouseWheel(object sender, MouseWheelEventArgs e) { e.Handled = false; }
2.在ScrollViewer中添加PreviewMouseWheel事件,并使用ScrollViewer.ScrollToVerticalOffset方法手动滚动。示例代码如下:
<ScrollViewer PreviewMouseWheel="ScrollViewer_PreviewMouseWheel"> <DataGrid> <!-- DataGrid的其他设置 --> </DataGrid> </ScrollViewer>
private void ScrollViewer_PreviewMouseWheel(object sender, MouseWheelEventArgs e) { e.Handled = true; var scrollViewer = (ScrollViewer)sender; scrollViewer.ScrollToVerticalOffset(scrollViewer.VerticalOffset - e.Delta); }
标签:sender,滚动,scrollViewer,翻页,ItemsControl,ScrollViewer,PreviewMouseWheel,Handled From: https://www.cnblogs.com/RX-ccA/p/18100265