Articles in this section
Category / Section

How to get the selected items using TapCommand in .NET MAUI ListView(SfListView)?

3 mins read

The .NET MAUI ListView control allows multiple item selections using the SelectionMode property. To access the selected items within the TapCommand, bind the SelectedItems property to your ViewModel, which holds the collection of currently selected items, and process them inside your command.

XAML

 <syncfusion:SfListView x:Name="listView" 
                ItemsSource="{Binding BookInfo}"
                SelectionMode="Multiple"
                SelectionGesture="Tap"
                SelectedItems="{Binding SelectedItems}"
                TapCommand="{Binding TapCommand}"
                ItemSize="100">
     <syncfusion:SfListView.ItemTemplate>
         <DataTemplate>
             <Grid Padding="10">
                 <Grid.RowDefinitions>
                     <RowDefinition Height="0.4*" />
                     <RowDefinition Height="0.6*" />
                 </Grid.RowDefinitions>
                 <Label Text="{Binding BookName}" FontAttributes="Bold" TextColor="Teal" FontSize="21" />
                 <Label Grid.Row="1" Text="{Binding BookDescription}" TextColor="Teal" FontSize="15"/>
             </Grid>
         </DataTemplate>
     </syncfusion:SfListView.ItemTemplate>
 </syncfusion:SfListView>

ViewModel

 public class BookInfoRepository
 {    
     private ObservableCollection<object>? selectedItems = new ObservableCollection<object>();

     public ObservableCollection<object>? SelectedItems
     {
         get { return selectedItems; }
         set { this.selectedItems = value; }
     }

     public ICommand TapCommand { get; set; }

     public BookInfoRepository()
     {         
         TapCommand = new Command(ExecuteTapCommamd);
     }

     private void ExecuteTapCommamd(object obj)
     {
         // SelectedItems contains the currently selected items.
         var _selectedItems = this.SelectedItems;
     }    
 }

Download the complete sample on GitHub

Conclusion:

I hope you enjoyed learning how to get the selected items using TapCommand in .NET MAUI ListView.

You can refer to our .NET MAUI ListView feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started with configuration specifications.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, try our 30-day free trial to check out our other controls.

Please let us know in the comments section below if you have any queries or require clarification. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied