Hi André Lacerda Murta Chaves,
We have analyzed the reported query “Access the selected items of SfListView in ViewModel” and you can achieve your requirement by using EventToCommand behaviors. Here, we have created a Command for SelectionChanged event of SfListView in ViewModel and bind the event to SfListView using Behaviors. We have already created a KB regarding this and you refer the below link for more information.
Code Example[C#]:
public class ContactsViewModel
{
Command< SfListView > selectionChangedCommand;
public Command< SfListView > SelectionChangedCommand
{
get { return selectionChangedCommand; }
protected set { selectionChangedCommand = value; }
}
public ContactsViewModel()
{
selectionChangedCommand = new Command< SfListView >(OnSelectionChanged);
}
private void OnSelectionChanged(SfListView listView)
{
var selectedItems= listView.SelectedItems;
}
} |
Code Example[XAML]:
<listView:SfListView ItemSize="70" ItemsSource="{Binding contactsinfo}">
<listView:SfListView.Behaviors>
<local:EventToCommandBehavior EventName="SelectionChanged" Command="{Binding SelectionChangedCommand}" CommandParameter="{Binding Source={x:Reference listView}}"/>
</listView:SfListView.Behaviors>
</listView:SfListView> |
For your assistance we have attached the working sample below.
Please let us know if you require further assistance.
Regards,
G.Muthu Kumaran.