Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/syncfusionexamples/xamarin-forms-listview-selected-item-binding-selectionchanging-event
This repository contains the sample about how to bind selectionchanging event in Xamarin.Forms ListView
https://github.com/syncfusionexamples/xamarin-forms-listview-selected-item-binding-selectionchanging-event
listview mvvm selected-item selection selectionchange xamarin xamarin-forms
Last synced: about 1 month ago
JSON representation
This repository contains the sample about how to bind selectionchanging event in Xamarin.Forms ListView
- Host: GitHub
- URL: https://github.com/syncfusionexamples/xamarin-forms-listview-selected-item-binding-selectionchanging-event
- Owner: SyncfusionExamples
- Created: 2019-08-05T03:45:43.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-02-15T13:43:03.000Z (12 months ago)
- Last Synced: 2024-04-14T12:07:22.442Z (10 months ago)
- Topics: listview, mvvm, selected-item, selection, selectionchange, xamarin, xamarin-forms
- Language: C#
- Homepage:
- Size: 500 KB
- Stars: 0
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Binding SelectionChanging event to Listview
In ListView, the [SelectionChanging](https://help.syncfusion.com/cr/cref_files/xamarin/Syncfusion.SfListView.XForms~Syncfusion.ListView.XForms.SfListView~SelectionChanging_EV.html) event will be raised when selecting an item at the execution time. MVVM for the `SelectionChanging` event can be achieved by binding through the event to command converter.
Refer [EventToCommand](https://www.syncfusion.com/kb/7523/how-to-turn-events-into-commands-with-behaviors-in-sflistview?_ga=2.49538854.1823797169.1563166718-1085055173.1562420655) knowledge base to create the command for event using behavior.
```
```
```
//ViewModel.cs
public class BookInfoRepository : INotifyPropertyChanged
{
private Command selectedItempublic Command SelectedItem
{
get { return this.selectedItem; }
set
{
this.selectedItem = value;
this.OnPropertyChanged("SelectedItem");
}
}public BookInfoRepository()
{
selectedItem = new Command(OnSelectionChanging);
}///
///To disable the selection for particular item
///
public void OnSelectionChanging(ItemSelectionChangingEventArgs obj)
{
var eventArgs = obj as ItemSelectionChangingEventArgs;
if (eventArgs.AddedItems.Count > 0 && eventArgs.AddedItems[0] == this.BookInfoCollection[0])
eventArgs.Cancel = true;
}
}
```
To know more about MVVM in ListView, please refer our documentation [here](https://help.syncfusion.com/xamarin/sflistview/mvvm)