TapGestureRecognizer doesn't fire Tapped event on child controls
See original GitHub issueDescription
I added a TapGestureRecognizer to a custom ContentView
which contains several other controls. I wondered why the Tapped
event is not getting fired on Android when I tap on the ContentView. The same code is working on Windows.
I figured out, that when I add the TapGestureRecognizer
to a child control which occupies alot of sapce the Tapped
event gets fired.
From my observation it looks like that the Tapped Event / TapGestureRecognizer will not be forwarded to its child controls.
This bug may be related to #6644 , #7466, #8004
Steps to Reproduce
- Create dotnet maui default project
- Add ContentView
- Add to the ContentView serveral controls
- register/add TapGestureRecognizer to ContentView.
- Tap on it and check if breakpoint gets hit on Tapped event
- Event is not fired
In the attached project TapGestureRecognizer_doesnt_fire_Tapped_event_on_child_controls.zip the ContentView contains the following control hierarchy:
- ContentView
- Grid
- Frame (occupies quite a lot of sapce)
- …
- Frame (occupies quite a lot of sapce)
- Grid
Adding the tapGestureRecognizer
directly to the content
(which is of type ContentView) will not fire the Tapped
event.
If you comment line control = ((content as ContentView).Children[0] as Grid).Children[0] as View
in the tapGestureRecognizer
gets added directly on the Frame. Tapping now on the ContentView will fire the Tapped
event.
private void MainPage_Loaded(object sender, EventArgs e)
{
View control = content; //content = ContentView
//control = ((content as ContentView).Children[0] as Grid).Children[0] as View; //Frame
var tapGestureRecognizer = new TapGestureRecognizer();
tapGestureRecognizer.Parent = control;
tapGestureRecognizer.Tapped += TapGestureRecognizer_Tapped;
control.GestureRecognizers.Add(tapGestureRecognizer);
}
Version with bug
6.0.312
Last version that worked well
Unknown/Other
Affected platforms
Android
Affected platform versions
android
Did you find any workaround?
Register the TapGestureRecognizer on all sub controls of the ContentView.
Relevant log output
No response
Issue Analytics
- State:
- Created a year ago
- Comments:7 (1 by maintainers)
Top GitHub Comments
@jfversluis The
TapGestureRecognizer
sample works on windows. The eventTapGestureRecognizer_Tapped
will be hit if you touch the provided area:I noticed that I forgot to remove some
StaticResource
s. I removed them from the sample, and updated the example.MauiApp1.zip
In addition I added for android an screenshot. Hope it helps
For the android platform you would need to comment in:
control = ((content as ContentView).Children[0] as Grid).Children[0] as View; //Frame
Edit: As I dont own an Iphone I don’t know the status of the issue on ios
Verified this on Visual Studio Enterprise 17.6.0 Preview 7.0. Repro on Android 13.0 with below Project: 8121.zip
Event
TapGestureRecognizer_Tapped
will be hit on Windows, but not on Android.