The CollectionView lacks TappedCommand. In my experience TappedCommand is required more that SelectionChangedCommand.
In ListView itemselected and itemtapped events are fired on tap. if developer consumes the tapped event he have to manually nullify the selected item.
CollectionView implementation should avoid this and allow TappedCommand even if SelectionMode is None.
TappedCommand is needed in cases where tapping on item results in some action like displaying a popup. If popup is cancelled by mistake the user can tap the same item again. Whereas with SelectionChangedCommand the user can't repeat same action on a CollectionView item.
We don't have plans to add this at this time. You can currently set a Command on the TapGestureRecognizer your DataTemplate uses to handle this sort of functionality.
We don't have plans to add this at this time. You can currently set a Command on the TapGestureRecognizer your DataTemplate uses to handle this sort of functionality.
TapGestureRecognizer doesn't fire on Android when used with CollectionView, seems like a very old known bug.
Any solution for this?
We don't have plans to add this at this time. You can currently set a Command on the TapGestureRecognizer your DataTemplate uses to handle this sort of functionality.
@pauldipietro I tried your suggested solution and on android the tapped Command does not fire when set on the data template - I have no way to interact with an item that is already the "selected item" - setting it back to null "on appearing" does not work for my architecture as i need to keep track of the selected item beyond the scope of the page. At the moment I have a hacky solution using the Clicked Event on the page which does work, and casting the sender object to the viewmodel binding context, but its a bit ugly.
@pauldipietro TapGestureRecognizer does not fire on android.
<DataTemplate>
<StackLayout>
<StackLayout.GestureRecognizers>
<TapGestureRecognizer Command="{Binding SelectionChangedCommand}" CommandParameter="{Binding .}"/>
</StackLayout.GestureRecognizers>
<Frame HasShadow="True" Margin="5,10,5,5" Padding="0" CornerRadius="10" BackgroundColor="LightGray">
<StackLayout Margin="10" Orientation="Horizontal">
<Label Text="{Binding LongName}"/>
<Label Text=" : "/>
<Label Text="{Binding ShortName}" />
</StackLayout>
</Frame>
</StackLayout>
</DataTemplate>
and I need this too:
I have no way to interact with an item that is already the "selected item" - setting it back to null
@pauldipietro
I have tried your soultion:
You can currently set a Command on the TapGestureRecognizer your DataTemplate uses to handle this sort of functionality.
however, there is problem about that:
tapped event is fired. however, the collection item doesn't set to Selected State.
as the event is consumed by TapGestureRecognizer, SelectableViewHolder.OnViewHolderClicked() will never called.
[tested in android]
Any update - we need to handle scenarios like adding tap on element that was previously selected. If we hook Selection changed event here - it doesn't fire second time. Introduce tapped gesture it has limitation. Feature should be considered for the next release.
Unbelievable, that such a basic feature does not work in 2020!
This is not just a nice-to-have, instead it is a must-have.
Work with Selection is lots of overhead, and TapGestureRecognizer does not work on Android.
Working with ListView is just a pain. PLEASE FIX!!!
Seconding the above comments. a Selection event reflects either programmatic or user selection, where as Tapped reflects strictly user selection. With the current CollectionView API there's no functionality available to identify strictly user selection.
Voting for this improvement as well. It is a must-have for lists.
And for now i'm using TapGestureRecognizer. Just in case anybody has issue on Android - set NumberOfTapsRequired to 1. This should help)
Most helpful comment
Voting for this improvement as well. It is a must-have for lists.
And for now i'm using TapGestureRecognizer. Just in case anybody has issue on Android - set NumberOfTapsRequired to 1. This should help)