Articles in this section
Category / Section

How to identify when end of the list is reached on scrolling in .NET MAUI ListView (SfListView) ?

3 mins read

The .NET MAUI ListView (SfListView) allows you to identify when the end of the list is reached while scrolling. By using the Changed event of ScrollAxisBase in VisualContainer, you can determine if you have reached the last item in the list based on the LastBodyVisibleLineIndex property and underlying collection count.

C#

You can get the item elements held by a scrollable visual container using the GetVisualContainer helper method.

public class ListViewBehavior : Behavior<SfListView>
{
    SfListView ListView;
    VisualContainer VisualContainer;
    bool isAlertShown = false;
    int totalItems = 0;
 
    protected override void OnAttachedTo(SfListView bindable)
    {
        ListView = bindable;
 
        ListView.Loaded += ListView_Loaded;
        VisualContainer = ListView.GetVisualContainer();
        VisualContainer.ScrollRows.Changed += ScrollRows_Changed;
 
        base.OnAttachedTo(bindable);
    }
 
    private void ListView_Loaded(object sender, EventArgs e)
    {
        //To include header if used
        var header = (ListView.HeaderTemplate != null && !ListView.IsStickyHeader) ? 1 : 0;
        //To include footer if used
        var footer = (ListView.FooterTemplate != null && !ListView.IsStickyFooter) ? 1 : 0;
        totalItems = ListView.DataSource.DisplayItems.Count + header + footer;
    }
 
    private void ScrollRows_Changed(object sender, ScrollChangedEventArgs e)
    {
        var lastIndex = VisualContainer.ScrollRows.LastBodyVisibleLineIndex;
 
        if (lastIndex != -1 && (lastIndex == totalItems - 1))
        {
            if (!isAlertShown)
            {
                App.Current.MainPage.DisplayAlert("Alert", "End of list reached...", "Ok");
                isAlertShown = true;
            }
        }
        else isAlertShown = false;
    }
}

Download the complete sample on GitHub.


Conclusion

I hope you enjoyed learning how to identify when the end of the list is reached on scrolling in the .NET MAUI ListView.

You can refer to our .NET MAUI ListView feature tour page to learn about its other groundbreaking feature representations and documentation, and how to quickly get started with configuration specifications. Explore our .NET MAUI ListView example to understand how to create and manipulate data.

For current customers, check out our components from the License and Downloads page. If you are new to Syncfusion®, try our 30-day free trial to check out our other controls.

Please let us know in the comments section if you have any queries or require clarification. Contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!


Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied