Init ListView with scroll position at end of list

MagnusKronaMagnusKrona SEMember ✭✭

I wonder if it's possible to init a ListView with the scroll position at the end of the list? I have a messaging like app and when I open up a conversation I would like to scoll to the end. I have a viewmodel that loads all the items and a ListView that is bound to that collection of items. I have tried to use to ScrollTo method when the items has been loaded but that seems to happen before the items actually have been rendered so nothing happens.

Any suggestions?

Tagged:

Best Answer

Answers

  • MitchMilamMitchMilam USMember ✭✭✭

    @MKrona try putting the ScrollTo in the OnAppearing event of your page.

  • MagnusKronaMagnusKrona SEMember ✭✭

    @MitchMilam Thanks for your answer. I have tried that. But the items are loaded async and OnAppearing happens before the items is fetched and bound to the list.

  • MitchMilamMitchMilam USMember ✭✭✭

    @MKrona can you add a Command to your ViewModel that you can call when the async operation completes?

  • MagnusKronaMagnusKrona SEMember ✭✭

    @MitchMilam i'm not sure I understand your suggestion. The items are loaded in the Viewmodel and assigned to an ObservableCollection. The ListViews ItemSource property is bound to the collection. I have tried to use MessagingCenter to send a message back to the view when the operation completes. But the message is sent before the list is populated with the items, so the scrolling action has no effect. So I tried to delay the message with a couple of hundred millisecs which works, but it doesn't look good and seems like a bad solution an workaround.
    Maybe I should take a whole different approch on how to do this...??

Sign In or Register to comment.