Пример #1
0
        private void OnUIElementManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs args)
        {
            double translationX = args.Cumulative.Translation.X - m_lastCapturedPoint.X;
            double translationY = args.Cumulative.Translation.Y - m_lastCapturedPoint.Y;

            if ((Math.Abs(translationX) > RECOGNIZE_DISTANCE) ||
                (Math.Abs(translationY) > RECOGNIZE_DISTANCE))
            {
                //Handle the case when one coordinat is zero
                if (translationX == 0f)
                {
                    if (translationY < 0f)
                    {
                        MoveTop.Raise(this, EventArgs.Empty);
                    }
                    else if (CanRaiseEvent())
                    {
                        MoveDown.Raise(this, EventArgs.Empty);
                        m_lastEventTimestamp = DateTime.UtcNow;
                    }

                    m_lastCapturedPoint = args.Cumulative.Translation;
                    return;
                }
                else if (translationY == 0f)
                {
                    if (translationX < 0f)
                    {
                        MoveLeft.Raise(this, EventArgs.Empty);
                    }
                    else if (CanRaiseEvent())
                    {
                        MoveRight.Raise(this, EventArgs.Empty);
                        m_lastEventTimestamp = DateTime.UtcNow;
                    }

                    m_lastCapturedPoint = args.Cumulative.Translation;
                    return;
                }

                //Handling logic for standard case
                float xToY = (float)translationX / (float)translationY;
                float yToX = (float)translationY / (float)translationX;
                if (Math.Abs(xToY) < 0.4f)
                {
                    if (translationY < 0f)
                    {
                        MoveTop.Raise(this, EventArgs.Empty);
                    }
                    else if (CanRaiseEvent())
                    {
                        MoveDown.Raise(this, EventArgs.Empty);
                        m_lastEventTimestamp = DateTime.UtcNow;
                    }

                    m_lastCapturedPoint = args.Cumulative.Translation;
                    return;
                }
                else if (Math.Abs(yToX) < 0.4f)
                {
                    if (translationX < 0f)
                    {
                        MoveLeft.Raise(this, EventArgs.Empty);
                    }
                    else if (CanRaiseEvent())
                    {
                        MoveRight.Raise(this, EventArgs.Empty);
                        m_lastEventTimestamp = DateTime.UtcNow;
                    }

                    m_lastCapturedPoint = args.Cumulative.Translation;
                    return;
                }
            }
        }