Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

TapGestureRecognizer - using NumberOfTapsRequired for double tap

$
0
0

Ideally I'm looking for a LongTap event or GestureRecognizer but as yet that doesn't exist in .Forms (hopefully next release!) so as a temporary workaround to my situation where my app normally uses tap to open and longtap (tap and hold) to show a popup context menu I thought I'd use tap to open and double tap to show the context menu as TapGestureRecognizer has a property NumberOfTapsRequired which should do the trick .. however I'm having problems working out how to do this.

Based on the following code, whilst the second doubletapped function is indeed only called when a double tap occurs, the first tapped function is called both for a tap and a double tap but without any way as far as I can tell to know in the tapped function that this is a double tap and hence to ignore it.

    public someObject() : base()
    {
        var tgr = new TapGestureRecognizer();
        tgr.NumberOfTapsRequired = 1;
        tgr.Tapped += tapped;
        GestureRecognizers.Add(tgr);

        var ttgr = new TapGestureRecognizer();
        ttgr.NumberOfTapsRequired = 2;
        ttgr.Tapped += doubletapped;
        GestureRecognizers.Add(ttgr);
    }
    private void tapped(object sender, EventArgs e)
    {
    // deal with tap
    }
    private void doubletapped(object sender, EventArgs e)
    {
        // deal with doubletap
    }

I would've hoped that perhaps in the EventArgs of tapped it would have the number of taps so I could then ignore double taps within it or is there some other way to deal with it?

Thanks


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>