ListView ScrollTo Groupheader

FreggarFreggar Member ✭✭
edited July 19 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.

Tagged:

Answers

  • 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,
    Mabrouk

  • 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 19

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

    Check the Tutorial:
    https://docs.microsoft.com/en-us/dotnet/api/xamarin.forms.listview.scrollto?view=xamarin-forms

    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.