Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

ListView ScrollTo Groupheader

FreggarFreggar Member ✭✭
edited July 2019 in Xamarin.Forms

Hi guys I'm currently running XF 3.6 on Android and got following problem.

I'm trying to scroll to a specific group via

lView.ScrollTo(null, group, ScrollToPosition.Start, true);

but this will just do nothing. I would expect a scroll to the group header instead. In my ListView some groups do not have any children so I can't just take the first item.
Is there any way to scroll to the group header?

If someone wants a sample code I can post one, but I leave it out for now since that just clutters the post.



  • MabroukMabrouk USMember ✭✭✭

    Hey @Freggar ,

    I know your problem. You need to pass in place of 'group' , the first element in the group.

    It should be something like :

    lView.ScrollTo( group?.FirstOrDefault(), ScrollToPosition.Start, true);

    I hope that helps,

  • FreggarFreggar Member ✭✭

    Thanks for the answer, sadly this does not work for groups that do not have any children.

  • MabroukMabrouk USMember ✭✭✭

    @Freggar said:
    Thanks for the answer, sadly this does not work for groups that do not have any children.

    are you working on ANDROID or FORMS ?

  • JarvanJarvan Member, Xamarin Team Xamurai
    edited July 2019

    It can be hardly to scroll to group header directly because the method is to scroll to a item in group.

    Check the Tutorial:

    Besides, why not choose to scroll to the last item before the group header you want to scroll. It shows the same effect.

    listview.ScrollTo(group[list_index][lastItem_index], group[list_index], ScrollToPosition.End,false);
  • FreggarFreggar Member ✭✭

    Yes the documentation is pretty straight about that, but I think it is not unreasonable to expect that kind of behavior. Anyway, my expectations are not important for this thread.

    I've actually already tried your proposed solution but that's just the same problem as before, slightly shifted. What if the previous group does not have any children?

    Well, one way would be to get the nearest previous group that does have children, but this will lead to inconsistent and confusing UX since where you will actually end up depends on a lot of seemingly random factors.

  • JarvanJarvan Member, Xamarin Team Xamurai
Sign In or Register to comment.