How to ScrollTo Listview item using Picker Xamarin Forms

Amasu 96 Reputation points
2021-03-09T16:19:34.547+00:00

Hi, Xamarin Forum,

Need help with something, I have a picker with a itemsource, that display the pages of my model, I need to bind the picker with the listview so when I click in a page on the picker I need to scroll the listview to that specific page, something like a book, when a select the page of the picker need to scrollto the page in the listview.

Please hope that someone can help me with this.

Regards

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,294 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,248 questions
0 comments No comments
{count} votes

Accepted answer
  1. Cole Xia (Shanghai Wicresoft Co,.Ltd.) 6,751 Reputation points
    2021-03-10T07:49:41.987+00:00

    Hello,

    Welcome to Microsoft Q&A!

    1 . Create the same data and bind it both on ListView and Picker .

       listView.ItemSource = list;  
       picker.ItemSource = list;  
    

    2 . Get the select item from Picker and then call listView.ScrollTo method .

       private void Picker_SelectedIndexChanged(object sender, EventArgs e)  
               {  
                   Picker picker = sender as Picker;  
         
                   var item = list[picker.SelectedIndex];  
         
                   listView.ScrollTo(item,ScrollToPosition.Center,true);  
               }  
    

    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful