Bubbling scroll events from a ListView to its parent

前端 未结 8 1429
深忆病人
深忆病人 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:58

    Ok been a while since I have been on SO but I had to comment on this. Any Preview event tunnels, so why are we bubbling it up? Stop the tunnel in the parent and be done with it. in the parent add a PreviewMouseWheel event.

         private void UIElement_OnPreviewMouseWheel(object sender, MouseWheelEventArgs e)
    {
        var scrollViewer = FindName("LeftPanelScrollViwer"); // name your parent mine is a scrollViewer
        ((ScrollViewer) scrollViewer)?.ScrollToVerticalOffset(e.Delta);
        e.Handled = true;
    }
    

提交回复
热议问题