ProcessUpEvent() public method

public ProcessUpEvent ( [ value ) : void
value [
return void
Exemplo n.º 1
0
 private void ControlOnPointerReleased(object sender, PointerRoutedEventArgs pointerRoutedEventArgs)
 {
     detector.ProcessUpEvent(pointerRoutedEventArgs.GetCurrentPoint(Control ?? Container));
     pointerRoutedEventArgs.Handled = true;
 }
Exemplo n.º 2
0
        private void AddGestureRecognizer()
        {
            var gesture = new GestureRecognizer() {
                AutoProcessInertia = true,
                GestureSettings = GestureSettings.Drag | GestureSettings.CrossSlide,
                CrossSlideHorizontally = true,
                CrossSlideThresholds = new CrossSlideThresholds { SpeedBumpEnd = 30 }
            };

            Point lastDragLocation;
            var lastDragTime = DateTime.Now;
            gesture.Dragging += (sender, args) => {
                switch (args.DraggingState) {
                    case DraggingState.Started:
                        lastDragLocation = args.Position;
                        lastDragTime = DateTime.Now;
                        break;

                    case DraggingState.Continuing: {
                            if (swipeDisplayed) {
                                SwipeHelp.FadeOut();
                                swipeDisplayed = false;
                            }

                            var delta = args.Position.X - lastDragLocation.X;
                            var time = DateTime.Now.Subtract(lastDragTime).TotalSeconds;
                            if (Math.Abs(delta) > 30 && time > 0) {
                                var velocity = delta / time;

                                lastDragLocation = args.Position;
                                lastDragTime = DateTime.Now;

                                Model.Zoomed(velocity);
                            }
                            break;
                        }
                }
            };
            gesture.CrossSliding += (sender, args) => {
                switch (args.CrossSlidingState) {
                    case CrossSlidingState.Started:
                        lastDragLocation = args.Position;
                        lastDragTime = DateTime.Now;
                        break;

                    case CrossSlidingState.Dragging: {
                            if (swipeDisplayed) {
                                SwipeHelp.FadeOut();
                                swipeDisplayed = false;
                            }

                            var delta = args.Position.X - lastDragLocation.X;
                            var time = DateTime.Now.Subtract(lastDragTime).TotalSeconds;
                            if (Math.Abs(delta) > 30 && time > 0) {
                                var velocity = delta / time;

                                lastDragLocation = args.Position;
                                lastDragTime = DateTime.Now;

                                Model.Zoomed(velocity);
                            }
                            break;
                        }
                }
            };

            GraphView.PointerPressed += (sender, args) => {
                GraphView.CapturePointer(args.Pointer);
                gesture.ProcessDownEvent(args.GetCurrentPoint(GraphView));
            };
            GraphView.PointerMoved += (sender, args) => {
                gesture.ProcessMoveEvents(args.GetIntermediatePoints(GraphView));
            };
            GraphView.PointerReleased += (sender, args) => {
                gesture.ProcessUpEvent(args.GetCurrentPoint(GraphView));
                GraphView.ReleasePointerCapture(args.Pointer);
            };
        }
        public static void Register(Frame frame, Func<Task> asyncBackAction, Func<Task> asyncForwardAction, NavigationHelperConfig config)
        {
            #region 标题栏后退键

            if (config.IsNavigateBackBySystemBackButton)
            {
                if (_systemNavigateBackHandlers.ContainsKey(frame) == false)
                {
                    var snm = SystemNavigationManager.GetForCurrentView();
                    snm.AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;
                    EventHandler<BackRequestedEventArgs> systemNavigateBackHandler = async (sender, e) =>
                    {
                        e.Handled = true;
                        if (asyncBackAction != null)
                        {
                            await asyncBackAction();
                        }
                    };
                    _systemNavigateBackHandlers.Add(frame, systemNavigateBackHandler);
                    snm.BackRequested += systemNavigateBackHandler;
                }
            }

            #endregion 标题栏后退键

            #region 设备后退键

            if (config.IsNavigateBackByHardwareBackButton)
            {
                if (HardwareButtonsHelper.IsUseable)
                {
                    if (_hardwareNavigateBackHandlers.ContainsKey(frame) == false)
                    {
                        EventHandler<BackPressedEventArgs> hardwareNavigateBackHandler = async (sender, e) =>
                        {
                            e.Handled = true;
                            if (asyncBackAction != null)
                            {
                                await asyncBackAction();
                            }
                        };
                        _hardwareNavigateBackHandlers.Add(frame, hardwareNavigateBackHandler);
                        HardwareButtons.BackPressed += hardwareNavigateBackHandler;
                    }
                }
            }

            #endregion 设备后退键

            CoreWindow window;
            if (_frameWindows.ContainsKey(frame))
            {
                window = _frameWindows[frame];
            }
            else
            {
                window = CoreWindow.GetForCurrentThread();
                _frameWindows[frame] = window;
            }

            #region 鼠标后退和前进

            if (config.IsNavigateBackByMouseXButton1 || config.IsNavigateForwardByMouseXButton2)
            {
                var isNavigateBackByMouseXButton1 = config.IsNavigateBackByMouseXButton1;
                var isNavigateForwardByMouseXButton2 = config.IsNavigateForwardByMouseXButton2;
                if (_mouseXButtonHandlers.ContainsKey(frame) == false)
                {
                    TypedEventHandler<CoreWindow, PointerEventArgs> mouseXButtonHandler = async (sender, e) =>
                    {
                        e.Handled = true;
                        switch (e.CurrentPoint.Properties.PointerUpdateKind)
                        {
                            case PointerUpdateKind.XButton1Released:
                                if (isNavigateBackByMouseXButton1)
                                {
                                    if (asyncBackAction != null)
                                    {
                                        await asyncBackAction();
                                    }
                                }
                                break;

                            case PointerUpdateKind.XButton2Released:
                                if (isNavigateForwardByMouseXButton2)
                                {
                                    if (asyncForwardAction != null)
                                    {
                                        await asyncForwardAction();
                                    }
                                }
                                break;
                        }
                    };
                    _mouseXButtonHandlers.Add(frame, mouseXButtonHandler);
                    window.PointerReleased += mouseXButtonHandler;
                }
            }

            #endregion 鼠标后退和前进

            #region 滑动后退和前进

            if (config.IsNavigateBackBySlideToRight || config.IsNavigateForwardBySlideToLeft)
            {
                var isNavigateBackBySlideToRight = config.IsNavigateBackBySlideToRight;
                var isNavigateForwardBySlideToLeft = config.IsNavigateForwardBySlideToLeft;

                var recognizer = new GestureRecognizer()
                {
                    GestureSettings = GestureSettings.CrossSlide,
                    CrossSlideHorizontally = true
                };
                PointerPoint startPoint = null;
                PointerPoint endPoint = null;
                if (_pointerPressedHandlers.ContainsKey(frame) == false)
                {
                    TypedEventHandler<CoreWindow, PointerEventArgs> pointerPressedHandler = (sender, e) =>
                    {
                        e.Handled = true;
                        switch (e.CurrentPoint.PointerDevice.PointerDeviceType)
                        {
                            case Windows.Devices.Input.PointerDeviceType.Touch:
                            case Windows.Devices.Input.PointerDeviceType.Pen:
                                var point = e.CurrentPoint;
                                startPoint = point;
                                recognizer.ProcessDownEvent(point);
                                break;
                        }
                    };
                    _pointerPressedHandlers.Add(frame, pointerPressedHandler);
                    window.PointerPressed += pointerPressedHandler;
                }
                if (_pointerMovedHandlers.ContainsKey(frame) == false)
                {
                    TypedEventHandler<CoreWindow, PointerEventArgs> pointerMovedHandler = (sender, e) =>
                    {
                        e.Handled = true;
                        switch (e.CurrentPoint.PointerDevice.PointerDeviceType)
                        {
                            case Windows.Devices.Input.PointerDeviceType.Touch:
                            case Windows.Devices.Input.PointerDeviceType.Pen:
                                recognizer.ProcessMoveEvents(e.GetIntermediatePoints());
                                break;
                        }
                    };
                    _pointerMovedHandlers.Add(frame, pointerMovedHandler);
                    window.PointerMoved += pointerMovedHandler;
                }
                if (_pointerReleasedHandlers.ContainsKey(frame) == false)
                {
                    TypedEventHandler<CoreWindow, PointerEventArgs> pointerReleasedHandler = (sender, e) =>
                    {
                        e.Handled = true;
                        switch (e.CurrentPoint.PointerDevice.PointerDeviceType)
                        {
                            case Windows.Devices.Input.PointerDeviceType.Touch:
                            case Windows.Devices.Input.PointerDeviceType.Pen:
                                var point = e.CurrentPoint;
                                endPoint = point;
                                recognizer.ProcessUpEvent(point);
                                break;
                        }
                    };
                    _pointerReleasedHandlers.Add(frame, pointerReleasedHandler);
                    window.PointerReleased += pointerReleasedHandler;
                }
                recognizer.CrossSliding += async (sender, e) =>
                {
                    if (e.CrossSlidingState == CrossSlidingState.Completed)
                    {
                        if (startPoint != null && endPoint != null)
                        {
                            var startX = startPoint.Position.X;
                            var endX = endPoint.Position.X;
                            if (startX < endX && isNavigateBackBySlideToRight)
                            {
                                if (asyncBackAction != null)
                                {
                                    await asyncBackAction();
                                }
                            }
                            if (startX > endX && isNavigateForwardBySlideToLeft)
                            {
                                if (asyncForwardAction != null)
                                {
                                    await asyncForwardAction();
                                }
                            }
                        }
                    }
                };
            }

            #endregion 滑动后退和前进
        }