locked
Init ListView with scroll position at end of list RRS feed

  • Question

  • User84899 posted

    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?

    Tuesday, April 28, 2015 12:40 PM

Answers

  • User3466 posted

    @MKrona The idea is you would add a FinishedLoading command to your ViewModel, which would call a method which would do the scrolling. You would then call that FinishedLoading command when your data is returned from your web service.

    @AdamKemp has a sample here. He uses ItemSelected in his example, but the concept is similar.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Tuesday, April 28, 2015 5:29 PM

All replies

  • User3466 posted

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

    Tuesday, April 28, 2015 12:53 PM
  • User84899 posted

    @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.

    Tuesday, April 28, 2015 12:58 PM
  • User3466 posted

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

    Tuesday, April 28, 2015 1:01 PM
  • User84899 posted

    @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...??

    Tuesday, April 28, 2015 4:28 PM
  • User3466 posted

    @MKrona The idea is you would add a FinishedLoading command to your ViewModel, which would call a method which would do the scrolling. You would then call that FinishedLoading command when your data is returned from your web service.

    @AdamKemp has a sample here. He uses ItemSelected in his example, but the concept is similar.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Tuesday, April 28, 2015 5:29 PM