Back to results for “Controls & Views”
.NET MAUI › Controls & Views

How do you handle item selection in a CollectionView?

Intermediate

Answer

Set SelectionMode to Single or Multiple, then bind SelectedItem (or SelectedItems) and handle SelectionChanged, or bind SelectionChangedCommand. In MVVM you typically bind SelectedItem to a view-model property and react in its setter or via a command, avoiding code-behind.
<CollectionView ItemsSource="{Binding Items}"
                SelectionMode="Single"
                SelectedItem="{Binding SelectedItem}"
                SelectionChangedCommand="{Binding OpenCommand}" />
Real-world example Tapping a row in a contacts list sets SelectedItem, which the view model uses to navigate to a detail page via its command.

Common follow-ups: What selection modes exist? | How do you clear selection?