maui
maui copied to clipboard
GestureRecognizers inhibit CollectionView Selection on Android
Description
In a CollectionView I use click to select an item and have a gesturerecognizer attached so as to be able to do other things in response to the click. A Windows build selects the item then calls the GestureRecognizer, on Android it does not select the item before calling the GestureRecognizer.
Steps to Reproduce
- Unzip the project from MAUIListEntry-TapGestureRecognizer.zip
- Cmpile and run it on Windows, click each item in the list in turn, you should see this:

- repeat on Android, this time clicking the items will do nothing and you'll just see this:

Also, the default line spacing seems to be wildly different between Windows and Android.
Version with bug
Release Candidate 2 (current)
Last version that worked well
Unknown/Other
Affected platforms
Android, I was not able test on other platforms
Affected platform versions
Android 11
Did you find any workaround?
No
Relevant log output
No response
verified repro on android with above project, vs 17.3.0 Preview 1.0 [32426.537.main].
still an issue on android with 17.3.0 Preview 2.0 [32507.29.main].
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.
Verified this on Visual Studio Enterprise 17.6.0 Preview 4.0. This issue does not repro on Windows 11, but repro on Android emulator (13.0-API 33) with below Project:
6644.zip
No response when clicking items on Android.

I hope this will get fixed soon, it has been over a year waiting and it is very important to use the CollectionView on Android. I want selection on single tap and navigation on 2 taps. This works easy on Windows but as the Android ignores selection when the GestureRecognizers are used for double tap it is useless.
I have the same issue on MacCatalyst as well
Verified this on with VS Version 17.8.5
One bug prevents me from using Border so i switch to the suggested Layout.
Then the next bug states i must use Border as the CollectionView wont generate a SelectedItem otherwise.
So in the stalemate i switch to a TapGestureRecognizer to substitute for SelectedItem only to find this problem and i cant use it either.
I spend as much time finding workaround for things rather than doing actual work.
Sometimes im shocked Maui is a released product.
@axa88 So sadly for you mate 😞 But you can do a workaround that aways works for me. Instead of use the selection command of the CollectionView, place a gesture recognizer on the first view of the item template, then you can send the binding object itself as command paramenter. Then you don't a selected item property on your VM to watch the selected item on your CollectionView. It should be something like this:
<CollectionView
...
SelectionMode="None">
<CollectionView.ItemTemplate>
<DataTemplate x:DataType="MyModelClass">
<Frame>
<Frame.GestureRecognizers>
<TapGestureRecognizer Command="{Binding Source={RelativeSource AncestorType={x:Type ContentPage}}, Path=BindingContext.ItemSelectedCommand}" CommandParameter="{Binding .}" />
</Frame.GestureRecognizers>
<Some components of the item layout/>
</Frame>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
Basically the ideia is access the binding context of the entire ContentPage (via AncestorType) on the CollectionView item and call the command from there. That's not a very good code, but it's what is aways working for me. And don't forget to accept the model which is used on the template of CollectionView as parameter on the command:
private ICommand itemSelectedCommand;
public ICommand ItemSelectedCommand =>
itemSelectedCommand ??= new Command<MyModelClass>((arg) => ItemSelectedCommandExecute(arg));
private void ItemSelectedCommandExecute(MyModelClass selected)
{
...
}
Hope that helps you.
@wesleykuhn
Does this work with a DataTemplateSelector and use of modern Border rather than Frame?
@wesleykuhn Does this work with a
DataTemplateSelectorand use of modernBorderrather thanFrame?
I never did it with DataTemplateSelector, maybe it will work, because it will seek for the parent of the item template view, using its type as criteria. Border has gesture recognizer, you can use it.
Still having this issue under Android, but works fine in Win.