2X faster development
The ultimate Xamarin UI toolkit to boost your development speed.
By default, 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 VisualContainer from SfListView and use the same way to get the ExtendedScrollView from VisualContainer. Please refer the below code snippets. C#
Click here to download the sample. |
2X faster development
The ultimate Xamarin UI toolkit to boost your development speed.
This page will automatically be redirected to the sign-in page in 10 seconds.
The above example works fine. However a scroll is animated when changing the ItemsSource with above code? Is there any way to avoid the animation?
Hi Samir,
We have checked the reported query “Need to disable the scrolling animation while changing the ItemsSource” from our side. You can achieve your requirement by using ScrollToRowIndex method where we have provided option to disable to animation while scrolling. You can get the value of ScrollLineIndex from the ScrollAxisBase in VisualContainer of SfListView before changing the ItemsSource. You can pass the value of ScrollLineIndex to ScrollToRowIndex and disable the animation while scrolling down the list as like below code example.
Code example[C#]:
public partial class MainPage : ContentPage
{
VisualContainer visualContainer;
public MainPage()
{
InitializeComponent();
visualContainer = listView.GetVisualContainer();
}
private void ChangeItemsSource_Clicked(object sender, EventArgs e)
{
var scrollLineIndex = visualContainer.ScrollRows.ScrollLineIndex;
var viewmodel = new ContactsViewModel();
listView.ItemsSource = viewmodel.EmployeeInfo;
listView.LayoutManager.ScrollToRowIndex(scrollLineIndex, true);
}
}
Note: This code example is applicable only after SfListView (v15.4.017).
Please let us know if you require further assistance.
Regards,
G.Muthu Kumaran.