1. 程式人生 > >ListBox攔截滾輪ScrollViewer滾動事件

ListBox攔截滾輪ScrollViewer滾動事件

 <ScrollViewer >
                <ListBox x:Name="CommentListBox" >

              </ListBox>    
</<ScrollViewer >

滾輪影響可修改

 <ScrollViewer >
                <ListBox x:Name="CommentListBox"   PreviewMouseWheel="CommentListBox_OnPreviewMouseWheel">

              </ListBox>    
</<ScrollViewer >
  private void CommentListBox_OnPreviewMouseWheel(object sender, MouseWheelEventArgs e)
        {
            if (e.Handled) return;
            e.Handled = true;
            var eventArg = new MouseWheelEventArgs(e.MouseDevice, e.Timestamp, e.Delta)
            {
                RoutedEvent = UIElement.MouseWheelEvent,
                Source = sender
            };
            var parent = ((Control)sender).Parent as UIElement;
            parent?.RaiseEvent(eventArg);
        }
https://stackoverflow.com/questions/1585462/bubbling-scroll-events-from-a-listview-to-its-parent