在UniversalApps(WP8)中完成操作

时间:2015-01-22 18:40:47

标签: windows-phone-8 touch

我正在尝试实现拖放功能。我的问题是ManipulationCompleted事件被解雇太晚了。当我用手指快速移动并释放触摸时,我的物体飞行了大约半秒钟。当我的手指被释放时,我想防止完全调用OnManipulationDelta。

 private void UIElement_OnManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
        {
            Debug.WriteLine("Changed");
            var element = e.OriginalSource as FrameworkElement;
            if (element != null)
            {
                TranslateTransform transform = element.RenderTransform as TranslateTransform;
                if (transform != null)
                {
                    transform.X += e.Delta.Translation.X;
                }
            }

        } 

2 个答案:

答案 0 :(得分:0)

尝试Touch_FrameReported。

是一种低级方法,开销很小且非常精确:Touch.FrameReported Event

示例:

private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
    Touch.FrameReported += Touch_FrameReported;
}

private void Touch_FrameReported(object sender, TouchFrameEventArgs e)
    {
        var point = e.GetPrimaryTouchPoint(this.CanvasLayer);

        if (TouchPanel.IsGestureAvailable)
        {
            GestureSample gesture = TouchPanel.ReadGesture();

            if (GestureType.Hold == gesture.GestureType)
            {
                IsActiveTouch = true;
                StartMoveWheel(point.Position);
                HoldWheel(sender, e);
            }
            else
            {
                this.CanvasLayer.ReleaseMouseCapture();
                IsActiveTouch = false;
            }
        }

        if (IsActiveTouch)
        {
            //Test if touch control is CanavasLayer
            if (point.TouchDevice.DirectlyOver == this.CanvasLayer)
            {
                switch (point.Action)
                {
                    case TouchAction.Move:
                        if (point != null) MoveWheel(point.Position);
                        break;
                    case TouchAction.Up:
                    default:
                        ExecuteCompletedMoveWheel();
                        break;
                }
            }
            else
            {
                ExecuteCompletedMoveWheel();
            }
        }
    }

答案 1 :(得分:0)

破坏惯性的解决方案;) 我已经完成了将ManipulationMode从All更改为TranslateX(因为我只想在X轴上翻译我的元素)