Google Resolved: ScrollTo not working with grouped ListView in Xamarin.Forms | SubramanyamRaju Xamarin & Windows App Dev Tutorials

Thursday 30 April 2020

Resolved: ScrollTo not working with grouped ListView in Xamarin.Forms

Introduction:

Sometimes ListView contains a grouped ItemsSource represented by a custom model class, and we may need to scroll to first item programatically.

Description:

Let's assume 'myListView' is binding with collection object 'EmployeeList<string,Employee>' which is from HomeViewModel.

And if we want to make myListView scroll to first grouped item with
'
ScrollTo (object item, object group, Xamarin.Forms.ScrollToPosition position, bool animated)' method, write below code


  • void ResetAtoZListScroll(object sender, EventArgs e)  
  •         {  
  •             if (myListView.ItemsSource != null && _homeViewModel.EmployeeList!=null)  
  •             {  
  •                 var fisrtItem = myListView.ItemsSource.Cast<object>().FirstOrDefault();  
  •                 myListView.ScrollTo(_homeViewModel.EmployeeList[0][0][0], _homeViewModel.EmployeeList[0], ScrollToPosition.Start, true);  
  •             }  
  •   
  •         }  

  • FeedBack Note: Please share your thoughts, what you think about this post, Is this post really helpful for you? I always welcome if you drop comments on this post and it would be impressive.


    Follow me always at @Subramanyam_B

    No comments:

    Post a Comment

    Search Engine Submission - AddMe