1. 程式人生 > >【WPF】ScrollViewer無法滾動的問題

【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控制元件不帶滾動的。。。那要你有何用??【攤手