I have equipped a Shape object in Xamarin Forms with a Tap Gesture Recognizer to react on tap events, however, it does not work. I have tried with Path, Polygone and Polyline objects. Wrapping the shape in a Frame works - but only if I tap on the area outside the shape. That's not what I want. Wrapping in a ContentView shows also no effect. Maybe that's all because shapes are still experimental in XF (you must set the Shapes_Experimental flag in the App class to use shapes)?
Here's a simple example working for the box but not for the triangle, tested on iOS:
public class TestPage : ContentPage
{
public TestPage()
{
var tgr = new TapGestureRecognizer();
tgr.Tapped += async (s, e) => {
await DisplayAlert("Info", "Tapped", "OK");
};
Polygon triangle = new Polygon
{
Points = new PointCollection(),
Fill = Brush.Blue,
};
triangle.Points.Add(new Point(0, 0));
triangle.Points.Add(new Point(100, 0));
triangle.Points.Add(new Point(50, 50));
triangle.GestureRecognizers.Add(tgr);
BoxView box = new BoxView
{
HeightRequest = 50,
Color = Color.Red
};
box.GestureRecognizers.Add(tgr);
Content = new StackLayout
{
Children = { triangle, box },
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center
};
}
}
Does anyone knows a solution or workaround how to make gestures work with shapes?