Bubbling scroll events from a ListView to its parent

前端 未结 8 1435
深忆病人
深忆病人 2020-11-28 06:25

In my WPF application I have a ListView whose ScrollViewer.VerticalScrollBarVisibility is set to Disabled. It is contained within a

8条回答
  •  眼角桃花
    2020-11-28 06:52

    There are different approaches depending on your exact situation, but I found this to work nicely. Assuming your basic situation is this:

    
    
        
            
                
        
    
    
    

    Raising MouseWheelEvent yourself during PreviewMouseWheel seems to force the ScrollViewer to work. I wish I knew why, it seems very counterintuitive.

    private void listTest_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
    {
        e.Handled = true;
        MouseWheelEventArgs e2 = new MouseWheelEventArgs(e.MouseDevice, e.Timestamp, e.Delta);
        e2.RoutedEvent = UIElement.MouseWheelEvent;
        listTest.RaiseEvent(e2);
    }
    

提交回复
热议问题