Child elements of scrollviewer preventing scrolling with mouse wheel?

前端 未结 4 1977

I\'m having a problem getting mouse wheel scrolling to work in the following XAML, which I have simplified for clarity:



        
4条回答
  •  时光取名叫无心
    2020-12-02 19:04

    You can also create a behavior and attach it to the parent control (in which the scroll events should bubble through).

    // Used on sub-controls of an expander to bubble the mouse wheel scroll event up 
    public sealed class BubbleScrollEvent : Behavior
    {
        protected override void OnAttached()
        {
            base.OnAttached();
            AssociatedObject.PreviewMouseWheel += AssociatedObject_PreviewMouseWheel;
        }
    
        protected override void OnDetaching()
        {
            AssociatedObject.PreviewMouseWheel -= AssociatedObject_PreviewMouseWheel;
            base.OnDetaching();
        }
    
        void AssociatedObject_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
        {
            e.Handled = true;
            var e2 = new MouseWheelEventArgs(e.MouseDevice, e.Timestamp, e.Delta);
            e2.RoutedEvent = UIElement.MouseWheelEvent;
            AssociatedObject.RaiseEvent(e2);
        }
    }
    
    
                
                    
                
    
    

提交回复
热议问题