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

Alternative for ItemDisappearing ItemAppearing Events and ScrollTo Method

Thread ID:





132898 Sep 27,2017 05:50 PM UTC Sep 28,2017 03:23 PM UTC Xamarin.Forms 1
Tags: SfListView
Bernard Simmons
Asked On September 27, 2017 05:50 PM UTC

I am looking to replace the standard ListView in my Xamarin Forms App with your SfListView. Everything was going along fine until I discovered that you do  not have the  ItemDisappearing and ItemAppearing Events. Is there an alternative? I use these events to determine when to display a control which when clicked will scroll the listview back to the to the 1st item in the list.

Also by the way I just noticed that your SfListView.ScrollTo want a double as it parameter. Can you also explain what this value is?



Muthu Kumaran Gnanavinayagam [Syncfusion]
Replied On September 28, 2017 03:23 PM UTC

Hi Bernard, 
We have checked with your reported queries. Please find the query details below. 
Using ScrollTo method 
You can programmatically scroll to the specified ScrollY position using the ScrollTo method. 
If your requirement is to scroll to a particular index then we would suggest you to use ScrollToRowIndex method. You can scroll to the desired index by passing the underlying data in DisplayItems.IndexOf method as like below code example. 
Code Example[C#]: 
int itemindex = listView.DataSource.DisplayItems.IndexOf(listView.SelectedItem); 
(listView.LayoutManager as LinearLayout).ScrollToRowIndex(itemindex); 
Please refer the below documentation link to know more information. 
Scrolling the list back to 1st item 
We could not understand your requirement clearly. Yet based on your query “Need to scroll to 1st index when particular index has reached”, we have created a sample to meet your requirement. In our sample we have used Changed event of ScrollAxisBase in VisualContainer to notify whether reached the particular item in the list has been reached based on LastBodyVisibleLineIndex property. By using Reflection you can get the VisualContainer from SfListView and use the same way to get ScrollAxisBase from VisualContainer 
When the particular index has been reached you can programmatically scroll to the first index as like below code snippets, 
Code Example[C#]: 
public partial class MainPage : ContentPage 
        VisualContainer visualContainer; 
        ScrollAxisBase scrollRows; 
        bool isItemReached = true; 
        public MainPage() 
            visualContainer = listView.GetType().GetRuntimeProperties().First(p => p.Name == "VisualContainer").GetValue(listView) as VisualContainer; 
            scrollRows = visualContainer.GetType().GetRuntimeProperties().First(p => p.Name == "ScrollRows").GetValue(visualContainer) as ScrollAxisBase; 
            scrollRows.Changed += ScrollRows_Changed; 
        private void ScrollRows_Changed(object sender, ScrollChangedEventArgs e) 
            var lastIndex = scrollRows.LastBodyVisibleLineIndex; 
            var header = (listView.HeaderTemplate != null && !listView.IsStickyHeader) ? 1 : 0; 
            var footer = (listView.FooterTemplate != null && !listView.IsStickyFooter) ? 1 : 0; 
            var totalItems = listView.DataSource.DisplayItems.Count + header + footer; 
            if ((lastIndex == totalItems - 1)) 
                if (isItemReached == true) 
                    (listView.LayoutManager as LinearLayout).ScrollToRowIndex(0); 
                    isItemReached = false; 
                isItemReached = true; 

Please let us know if you require further assistance. 
G.Muthu Kumaran. 


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