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. Image for the cookie policy date

Alternative for ItemDisappearing ItemAppearing Events and ScrollTo Method

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?



1 Reply

MK Muthu Kumaran Gnanavinayagam Syncfusion Team 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. 

Live Chat Icon For mobile
Up arrow icon