We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to turn Events into Commands with Behaviors in SfListView?

Platform: Xamarin.Forms |
Control: SfListView
Tags: event, mvvm, commands

In SfListView, Event can be turned into the Command using Behaviors to follow the MVVM pattern.

To achieve this, need to create a Command for the ItemTapped event of SfListView in ViewModel.

public class ContactsViewModel
        Command<ItemTappedEventArgs> tapCommand;
        public Command<ItemTappedEventArgs> TapCommand
            get { return tapCommand; }
            protected set { tapCommand = value; }
        public ContactsViewModel()
            tapCommand = new Command<Syncfusion.ListView.XForms.ItemTappedEventArgs>(OnTapped);
        ///To display tapped item content
        public void OnTapped(ItemTappedEventArgs eventArgs)
            var name =(eventArgs.ItemData as Contacts).ContactName;
            var number = (eventArgs.ItemData as Contacts).ContactNumber;
            var display = Application.Current.MainPage.DisplayAlert(name, "Number:"+number, "Ok");



And associate that Command to the appropriate Event of SfListView using Behaviors like below.



<syncfusion:SfListView x:Name="listView" >
    <local:EventToCommandBehavior EventName="ItemTapped"
                                  Command="{Binding TapCommand}"
                                  Converter="{StaticResource EventArgs}" >


Now, when tapped on the ListViewItem, corresponding Command in ViewModel will be invoked automatically and performed the desired operation as shown in below screenshot.


Tapped ListViewItem corresponding command in ViewModel.

Click here to download the sample.

2X faster development

The ultimate Xamarin UI toolkit to boost your development speed.
You must log in to leave a comment
Dave Friedel
Oct 29, 2017

To make this a tad more helpful, one should reference the "local:EventToCommandBehavior" which is outlined on this page.  https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/behaviors/reusable/event-to-command-behavior/

Dave Friedel
Oct 29, 2017

To Be Honest - you should make a Command Property like other vendors.  Make your controls robust as possible to make the developer's lives easier.

Muthu Kumaran Gnanavinayagam [Syncfusion]
Nov 02, 2017

Hi Dave,


Thanks for your valuable feedback. We are already have plan to provide Command for the applicable events. This feature is in queue and will implement in any our upcoming release.



G.Muthu Kumaran.

Feb 08, 2019

Any progress?

Jayaleshwari N [Syncfusion]
Feb 08, 2019

Hi Steve,


We have provided Tap Command and Hold Command which is available from our Syncfusion version You can refer the following user guide documentation which provides details about Tap and Hold command.





Jayaleshwari N


Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile