Ejemplo n.º 1
0
        private void PreviewMouseWheel(object sender, MouseWheelEventArgs e)
        {
            var scrollViewer = ResHelper.FindVisualChildren <ScrollViewer>(AssociatedObject).FirstOrDefault();

            if (scrollViewer == null)
            {
                return;
            }

            const float tolerance = 1e-4f;

            var scrollPos = scrollViewer.ContentVerticalOffset;

            if (
                (!(Math.Abs(scrollPos - scrollViewer.ScrollableHeight) < tolerance) || e.Delta >= 0) &&
                (!(Math.Abs(scrollPos) < tolerance) || e.Delta <= 0)
                )
            {
                return;
            }

            if (!(((Control)sender).Parent is UIElement parent))
            {
                return;
            }

            e.Handled = true;
            var e2 = new MouseWheelEventArgs(e.MouseDevice, e.Timestamp, e.Delta)
            {
                RoutedEvent = UIElement.MouseWheelEvent,
                Source      = sender
            };

            parent.RaiseEvent(e2);
        }