2X faster development
The ultimate Xamarin UI toolkit to boost your development speed.
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); } ///<summary> ///To display tapped item content ///</summary> 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"); } } C#
And associate that Command to the appropriate Event of SfListView using Behaviors like below.
XAML <syncfusion:SfListView x:Name="listView" > <syncfusion:SfListView.Behaviors> <local:EventToCommandBehavior EventName="ItemTapped" Command="{Binding TapCommand}" Converter="{StaticResource EventArgs}" > </local:EventToCommandBehavior> </syncfusion:SfListView.Behaviors> </syncfusion:SfListView>
Now, when tapped on the ListViewItem, corresponding Command in ViewModel will be invoked automatically and performed the desired operation as shown in below screenshot. Screenshot: Click here to download the sample. |
2X faster development
The ultimate Xamarin UI toolkit to boost your development speed.
This page will automatically be redirected to the sign-in page in 10 seconds.
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/
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.
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.
Regards,
G.Muthu Kumaran.
Any progress?
Hi Steve,
We have provided Tap Command and Hold Command which is available from our Syncfusion version 16.1.0.24. You can refer the following user guide documentation which provides details about Tap and Hold command.
https://help.syncfusion.com/xamarin/sflistview/mvvm#commands
Regards,
Jayaleshwari N