Forum Discussion

hacka87's avatar
hacka87
Contributor
6 years ago

How to Scroll in a Xamarin.Forms.ListVIew ?

Hello !

 

I am trying to scroll to the bottom of the ListView.

 

Using the TouchItemXY(index, X, Y) automatically scrolls to the item specified by the index.

There is one case when the Scroll is done, but the Item cannot be touched. The error is "Could not touch the point at (-2, -2) because it is out of the control bounds".

 

Do you know how to use the ScrollTo(System.Object Item, Xamarin.Forms.ScrollToPosition position, boolean animated); method on listview?

 

Best Regards,

 

 

 

 

  • Hi
    You can use this code
    function Test()
    {
      let listview = Mobile.Device()...XFObject("listView")
      let item = listview.ItemsSource.Item(0).Item(10) // e.g.11th item in a first group
      let position = 0 //Scroll to make a specified list item visible.
      listview.ScrollTo(item, position, true)
    }
    or
    function Test()
    {
      let listview = Mobile.Device()...XFObject("listView")
      for (let i = 0; i < listview.ItemsSource.Item(0).Count; i++)
      {
        let item = listview.ItemsSource.Item(0).Item(10)
        if (item.FullName == "Item 11")
          listview.ScrollTo(item, 0, true)
      }
    }

  • IStaroverov's avatar
    IStaroverov
    SmartBear Alumni (Retired)

    Hi
    You can use this code
    function Test()
    {
      let listview = Mobile.Device()...XFObject("listView")
      let item = listview.ItemsSource.Item(0).Item(10) // e.g.11th item in a first group
      let position = 0 //Scroll to make a specified list item visible.
      listview.ScrollTo(item, position, true)
    }
    or
    function Test()
    {
      let listview = Mobile.Device()...XFObject("listView")
      for (let i = 0; i < listview.ItemsSource.Item(0).Count; i++)
      {
        let item = listview.ItemsSource.Item(0).Item(10)
        if (item.FullName == "Item 11")
          listview.ScrollTo(item, 0, true)
      }
    }