【WPF】ScrollViewer无法滚动的问题

还需要给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控件不带滚动的。。。那要你有何用??【摊手

posted @ 2017-01-23 09:38  霍莉雪特  阅读(1766)  评论(0编辑  收藏  举报