Xamarin Forms - SelectionChangedCommand not firing for CollectionView
Couple of things that worked at my side (additionally to the SelectionMode = Single
):
Make sure your Command' signature is
<object>
at your PageModel and do any cast according to your needs (specially if your collection becomes more complex).Also at your XAML you want to give your CollectionView a name and use the SelectedItem property.
SelectionChangedCommandParameter="{Binding SelectedItem, Source={x:Reference cvTagsCollectionView}}"
I use your code and created a demo on my side, I add the widthRequest
and HeightRequest
to make the collectionView work:
<CollectionView
HeightRequest="170"
WidthRequest="200"
SelectionMode="Single"
SelectionChangedCommand="{Binding SelectedTagChangedCommand}"
ItemsSource="{Binding Tags}"
>
The SelectionChangedCommand
did triggered after I click different items in the CollectionView.
I uploaded a sample here and you can check it: collectionView-selectItemChanged-xamarin.forms