In Xamarin Forms how do I find out the location of a tap (within an image, say)?My code is:
var tapGestureRecognizer = new TapGestureRecognizer();
tapGestureRecognizer.Tapped += OnTapGestureRecognizerTapped;
image.GestureRecognizers.Add(tapGestureRecognizer);
...
...
void OnTapGestureRecognizerTapped(object sender, EventArgs args)
{ ... }
args.Parameter returns null (for iOS). I did not find any docs for Parameter. In the handler I tried changing EventArgs to TappedEventArgs but then did not compile. Also tried casting args to TappedEventArgs but that did not change anything.
Setup Xamarin Community ToolkitOpen an existing project, or create a new project using the Blank Forms App template. In the Solution Explorer panel, right click on your project name and select Manage NuGet Packages. Search for Xamarin. CommunityToolkit, and choose the desired NuGet Package from the list.
At the moment of writing this answer it seems that there is no way of receiving the coordinates of the tap in XamarinForms without platform specific code. There are third party libraries (mentioned here) which provide this information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With