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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Programmatic scrolling from ViewModel

Thread ID:





131681 Jul 23,2017 01:58 PM UTC Jul 24,2017 11:00 AM UTC Xamarin.Forms 1
Tags: SfListView
Asked On July 23, 2017 01:58 PM UTC

Is there a way to scroll to an index / item from viewmodel ? I am using mvvm and having some action on selecteditem in viewmodel. once it is completed, i would like to scroll to next item within viewmodel 

Dinesh Babu Yadav [Syncfusion]
Replied On July 24, 2017 11:00 AM UTC

Hi Emil, 
Thank you for contacting Syncfusion support. 
The reported requirement “Scroll to next selected item in ViewModel using MVVM pattern” can be achieved by using Command property and by passing the SfListView events through Behaviors to ViewModel. By using SelectionChanged event and passing the EventName as SelectionChanged in the custom behavior class(EventToCommandBehavior) as like below code snippet which passes the ItemSelectionChangedEventArgs as parameter of SelectionChangedCommand command in ViewModel class. Also, you can access the SfListView in ViewModel class through LoadedCommand as like below code snippet in which ListView parameter is passed as argument through Behaviors and CustomConvertor. So, whenever an item is selected, you can be get the SelectedItem and then you can scroll to next item as like below code snippet using ScrollToRowIndex method.  
Code Example[XAML]: 
<listView:SfListView x:Name="listView" ItemSize="70" ItemSpacing="0,0,5,0" 
                           ItemsSource="{Binding contactsinfo}"> 
     <local:EventToCommandBehavior EventName="Loaded" 
                                   Command="{Binding LoadedCommand}" 
                                   Converter="{StaticResource EventArgs}" /> 
     <local:EventToCommandBehavior EventName="SelectionChanged" 
                                   Command="{Binding SelectionChangedCommand}" 
                                   Converter="{StaticResource EventArgs}" /> 
Code Example[C#]: 
public void OnListViewLoaded(SfListView listView) 
  ListView = listView; 
public async void OnSelectionChanged(ItemSelectionChangedEventArgs eventArgs) 
  if (ListView.SelectedItem != null) 
     index = contactsinfo.IndexOf(ListView.SelectedItem as Contacts); 
  await Task.Delay(500); 
  (ListView.LayoutManager as LinearLayout).ScrollToRowIndex(index + 1); 
For your reference, we have attached the sample and you can download it form the below link. 
Please let us know if you require further assistance. 
Dinesh Babu Yadav 


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.

Please sign in to access our forum

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

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