Search code examples
listviewxamarinxamarin.formssyncfusion

How to get visible items from Syncfusion list view?


I am working in Xamarin.Forms project and using Syncfusion SfListView control for a list.

Now I want to get visible items only on initial base and after scrolling the list view. Means after scrolling stop I need the visible items to update by getting updates through API.

How can I achieve this in Xamarin.Forms Syncfusion SfListView?

Could anyone please give the solution for it?

Thanks.


Solution

  • We would like to inform you that you can get the items created on load from the Children property of the VisualContainer. Also, you can get the information of the last visible item using the VisualContainer.ScrollRows.LastBodyVisibleLineIndex property.

    The VisualContainer.Children will have the details of the visible items.

    public class Behavior : Behavior<ContentPage> 
        { 
            SfListView ListView; 
            VisualContainer VisualContainer; 
         
            protected override void OnAttachedTo(ContentPage bindable) 
            { 
                ListView = bindable.FindByName<SfListView>("listView"); 
                VisualContainer = ListView.GetVisualContainer(); 
                ListView.ScrollStateChanged += ListView_ScrollStateChanged; 
                base.OnAttachedTo(bindable); 
            } 
         
            private void ScrollView_Scrolled(object sender, ScrolledEventArgs e) 
            { 
            } 
         
            private void ListView_ScrollStateChanged(object sender, ScrollStateChangedEventArgs e) 
            { 
                if (e.ScrollState == ScrollState.Idle) 
                { 
                    var visibleItems = VisualContainer.Children; 
                    var lastVisibleItem = VisualContainer.ScrollRows.LastBodyVisibleLineIndex; 
                } 
            } 
        }