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.
Unfortunately, activation email could not send to your email. Please try again.

How to pass selected itens to viewmodel?

Thread ID:

Created:

Updated:

Platform:

Replies:

130258 May 2,2017 11:58 PM May 8,2017 12:43 AM Xamarin.Forms 3
loading
Tags: SfListView
André Lacerda Murta Chaves
Asked On May 2, 2017 11:58 PM

Hello guys,

I'm doing this the wrong way in the code behind:

private void ListView_OnSelectionChanged(object sender, ItemSelectionChangedEventArgs e)
        {
            viewModel.SelectedItens = listView.SelectedItems;
        }

How can I bind this?

Muthu Kumaran Gnanavinayagam [Syncfusion]
Replied On May 5, 2017 03:28 AM

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. 


André Lacerda Murta Chaves
Replied On May 5, 2017 10:47 AM

Thanks a lot!

That solved my problem.

Dinesh Babu Yadav [Syncfusion]
Replied On May 8, 2017 12:43 AM

Hi Andre, 
 
Thanks for the update. 
 
Regards, 
Dinesh Babu Yadav 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

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.

;