还需要给ScrollViewer注册一个鼠标滚轮事件!
XAML:
<ScrollViewer x:Name="scrollViewer" Width="950" Height="480" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Hidden" PreviewMouseWheel="ScrollViewer_PreviewMouseWheel">
// ......
</ScrollViewer >
后台代码实现:
// 使得ScrollViewer可以滚动
private void ScrollViewer_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
{
var eventArg = new MouseWheelEventArgs(e.MouseDevice, e.Timestamp, e.Delta);
eventArg.RoutedEvent = UIElement.MouseWheelEvent;
eventArg.Source = sender;
scrollViewer.RaiseEvent(eventArg);
}
吐个槽:居然还有ScrollView控件不带滚动的。。。那要你有何用??【摊手