Skip to content

This repository contains the sample about how to maintain scroll position on changing ItemsSource in Xamarin.Forms ListView

Notifications You must be signed in to change notification settings

SyncfusionExamples/Maintaing-scroll-position-on-changing-itemssource-xamarin.forms-listview

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

Maintain the scroll position when updating ItemsSource at runtime

The SfListView have scrolled to top automatically when changing the ItemsSource at runtime. However, you can maintain the same scrolled position by using the ScrollY value of ExtendedScrollView from the VisualContainer. After changing the ItemsSource, you can pass the ScrollY value to ScrollTo method of SfListView and scroll back to the same position.

For horizontal orientation, use the ScrollX value of ExtendedScrollView.

By using Reflection, get the value of ScrollOwner from VisualContainer and use it.

using Syncfusion.ListView.XForms.Control.Helpers;
public partial class MainPage : ContentPage
{
    ExtendedScrollView scrollView;

    public MainPage()
    {
        InitializeComponent();
        scrollView = listView.GetScrollView();
    }

    private void ChangeItemsSource_Clicked(object sender, EventArgs e)
    {
        var viewModel = new ContactsViewModel();
        listView.ItemsSource = viewModel.EmployeeInfo;
        listView.ScrollTo(scrollView.ScrollY);
    }
}

To know more about Scrolling in ListView, please refer our documentation here

About

This repository contains the sample about how to maintain scroll position on changing ItemsSource in Xamarin.Forms ListView

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages