Articles in this section
Category / Section

How to notify item selection using MVVM in Xamarin.Forms ListView?

1 min read

In Xamarin. Forms ListView, you can find whether the item is selected or not by maintaining bool property in model class. The property value will be updated using selection events like SelectionChanging, SelectionChanged.


<ContentPage xmlns:syncfusion="clr-namespace:Syncfusion.ListView.XForms;assembly=Syncfusion.SfListView.XForms" >
                  <local:CustomConverter x:Key="EventArgs" />
         <syncfusion:SfListView x:Name="listView" ItemsSource="{Binding contactsinfo}">
                      <local:EventToCommandBehavior EventName="SelectionChanged" 
                                        Command="{Binding OnSelectionChangedCommand}"
                                        Converter="{StaticResource EventArgs}" />



public Command<object> SelectionChangedCommand
    get { return selectionChangedCommand; }
    protected set { selectionChangedCommand = value; }
public ContactsViewModel()
    selectionChangedCommand = new Command<object>(OnSelectionChangedCommand);
    contactsinfo = new ObservableCollection<Contacts>();
public void OnSelectionChangedCommand (object obj)
    var eventArgs = obj as ItemSelectionChangedEventArgs;
    for (int i = 0; i < eventArgs.RemovedItems.Count; i++)
       var item = eventArgs.RemovedItems[i] as Contacts;
       if (item.IsSelected)
          item.IsSelected = false;
          App.Current.MainPage.DisplayAlert("Message", "Item removed from selected item", "ok");
    for (int i = 0; i < eventArgs.AddedItems.Count; i++)
       var item = eventArgs.AddedItems[i] as Contacts;
       if (!item.IsSelected)
           item.IsSelected = true;
           App.Current.MainPage.DisplayAlert("Message", "Item added into selected item", "ok");


Screenshots :

Sample Link : Notify selection using MVVM








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