/// <summary> /// Handles that the dragged pointing device is over in the target UI element. /// For reference the DragOver event is raised periodically. /// </summary> /// <param name="currentPosition">The current pointing device position relative to the target UI element.</param> /// <param name="hoverEventMode">A HoverEventMode.</param> /// <param name="hoverTime">A HoverTime.</param> /// <param name="hoverWidth">A HoverWidth.</param> /// <param name="hoverHeight">A HoverHeight.</param> /// <param name="setIsHover">An action that sets a IsHover.</param> /// <param name="hoverCallback">A callback action that is called when Hover is detected.</param> public void ProcessOver(Point currentPosition, HoverEventMode hoverEventMode, TimeSpan hoverTime, double hoverWidth, double hoverHeight, Action <bool> setIsHover, Action <Point, long, Point, long> hoverCallback) { if (setIsHover == null) { throw new ArgumentNullException("setIsHover"); } if (hoverCallback == null) { throw new ArgumentNullException("hoverCallback"); } // Gets the point in screen coordinates. Point currentPositionInScreen = PointToScreen(currentPosition); // Checks whether the current position is in the hover rectangle... Vector allowedMoveDistance = new Vector(hoverWidth, hoverHeight); if (BasePositionInScreen == null || !IsHover(allowedMoveDistance, BasePositionInScreen.Value, currentPositionInScreen)) { // Resets the base position related values. BasePositionInScreen = currentPositionInScreen; BaseTicks = DateTime.Now.Ticks; _isRaisedAtBasePosition = false; // Sets that it is not hover. setIsHover(false); return; } // If the hover event mode is once and the hover event is already raised in the target UI element. if (hoverEventMode == HoverEventMode.Once && IsRaisedAfterEnter) { return; } // If the hover event mode is normal and the hover event is already raised at the BasePosition if (hoverEventMode == HoverEventMode.Normal && _isRaisedAtBasePosition) { return; } // Checks whether the elapsed ticks are greater than the hover time. long currentTicks = DateTime.Now.Ticks; if (!IsHover(hoverTime.Ticks, BaseTicks, currentTicks)) { return; } // Sets that it is hover. setIsHover(true); // Calls the hover callback. CallHoverCallback(hoverCallback, currentPositionInScreen, currentTicks); // Sets the raised flag. IsRaisedAfterEnter = true; _isRaisedAtBasePosition = true; // Resets the base ticks. BaseTicks = DateTime.Now.Ticks; }
/// <summary> /// Sets a value that describes how hover event is raised. /// </summary> /// <param name="obj">The target element.</param> /// <param name="value">A value that describes how hover event is raised.</param> /// <seealso cref="HoverEventMode"/> public static void SetHoverEventMode(DependencyObject obj, HoverEventMode value) { obj.SetValue(HoverEventModeProperty, value); }