Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Windows Phone Silverlight: Poor Man's Double-Tap

DZone's Guide to

Windows Phone Silverlight: Poor Man's Double-Tap

· Mobile Zone ·
Free Resource

I have seen a lot of articles about gestures but they require third party libraries or complex coding approaches.  What I am going to present here isn’t strictly elegant or necessarily the best approach, but this is the way we would catch this type of event when we were still dealing with message loops.

For the app that I have been working on I need to take action on the double-tap of a list item. The first question you have to ask your self is what a double-tap really is. It is in simplest terms it is two taps within a specified amount of time.  Given that I created a page level variable that holds a DateTime.  If you set it each time the MouseEnter event fires and check it against the previous value you can imply a double tap.  The code below is about as simple as it gets.

private void list_MouseEnter(object sender, MouseEventArgs e)
{
    DateTime tempTapTime = DateTime.Now;
    if(tempTapTime.Subtract(_lastTapTime).TotalMilliseconds < 250)
    {
        if (listEvaluations.SelectedIndex > -1)
        {
            // Do something
        }
    }
    else
    {
        _lastTapTime = tempTapTime;
    }
}


Source:  http://geekswithblogs.net/tmurphy/archive/2011/10/07/windows-phone-silverlight-poor-mans-double-tap.aspx

Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}