Search code examples
windows-phone-7

ManipulationDelta event only fires after a threshold is passed


I am trying to write some code that will allow the user to draw on the touch screen.

When using either GestureService or ManipulationStarted/Delta, there's a "pause" that occurs when the user starts moving their finger - only when the finger is far enough from the point in which it started, only then do you start getting ManipulationDelta events (and like I said, same deal is true for GestureService).

What can I do to avoid this threshold? It really does not work well with drawing code.


Solution

  • Just blogged about it as I have come across similar questions on AppHub Forum. https://invokeit.wordpress.com/2012/04/27/high-performance-touch-interface-wpdev-wp7dev/

    Manipulation Delta and Gesture services are high level touch interfaces. If you want performance, consider using low level interfaces: Touch and an event called TouchReported. I tend to use them mostly (for drawing / position detection) in many of my projects

    The event you want to plug in to detech touch is

    Touch.FrameReported += Touch_FrameReported;
    

    You can do this in Loaded event. Here's the implementation of the Touch_FrameReported handler. WorkArea is Canvas in this. I have also used this in conjugation with WritableBitmap

    private void Touch_FrameReported(object sender, TouchFrameEventArgs e)
    {
        try
        {
            // Determine if finger / mouse is down
            point = e.GetPrimaryTouchPoint(this.workArea);
    
            if (point.Position.X < 0 || point.Position.Y < 0)
                return;
    
            if (point.Position.X > this.workArea.Width || point.Position.Y > this.workArea.Height)
                return;
    
            if (this.lbLetter.SelectedIndex == -1)
                return;
    
            switch (point.Action)
            {
                case TouchAction.Down:
                    draw = true;
                    old_point = point;
                    goto default;
    
                case TouchAction.Up:
                    draw = false;
                    break;
    
                default:
                    Draw();
                    break;
            }
        }
        catch
        {
            MessageBox.Show("Application encountered error processing last request.");
        }
    }
    

    This works lot better than high level interfaces.