예제 #1
0
        private static void HandleMouseHorizontalWheel([NotNull] Window handledWindow, IntPtr wParam)
        {
            if (handledWindow == null)
            {
                throw new ArgumentNullException(nameof(handledWindow));
            }

            int tilt = (short)Win32.HiWord(wParam);

            if (tilt == 0)
            {
                return;
            }

            IInputElement element = Mouse.DirectlyOver;

            if (element == null)
            {
                return;
            }

            if (!(element is UIElement))
            {
                element = VisualTreeHelpers.FindAncestor <UIElement>(element as DependencyObject);
            }
            if (element == null)
            {
                return;
            }

            // make sure the ancestor is this window
            if (!ReferenceEquals(VisualTreeHelpers.FindAncestor <Window>((DependencyObject)element), handledWindow))
            {
                return;
            }

            var ev = new MouseHorizontalWheelEventArgs(Mouse.PrimaryDevice, Environment.TickCount, tilt)
            {
                RoutedEvent = PreviewMouseHorizontalWheelEvent
                              //Source = handledWindow
            };

            // first raise preview
            element.RaiseEvent(ev);
            if (ev.Handled)
            {
                return;
            }

            // then bubble it
            ev.RoutedEvent = MouseHorizontalWheelEvent;
            element.RaiseEvent(ev);
        }
        private static void HandleMouseHorizontalWheel(IntPtr wParam)
        {
            int tilt = Win32.HiWord(wParam);

            if (tilt == 0)
            {
                return;
            }

            IInputElement element = Mouse.DirectlyOver;

            if (element == null)
            {
                return;
            }

            if (!(element is UIElement))
            {
                element = VisualTreeHelpers.FindAncestor <UIElement>(element as DependencyObject);
            }
            if (element == null)
            {
                return;
            }

            var ev = new MouseHorizontalWheelEventArgs(Mouse.PrimaryDevice, Environment.TickCount, tilt)
            {
                RoutedEvent = PreviewMouseHorizontalWheelEvent
                              //Source = handledWindow
            };

            // first raise preview
            element.RaiseEvent(ev);
            if (ev.Handled)
            {
                return;
            }

            // then bubble it
            ev.RoutedEvent = MouseHorizontalWheelEvent;
            element.RaiseEvent(ev);
        }