locked
ListView, mantain scroll position when refresh RRS feed

  • Question

  • User216212 posted

    Hi all, is it possible to mantain the current position of a ListView when some items are inserted on top of the ItemsSource?

    Something like this CurrentList.Insert (0, postsGrouped) refresh the UI but moves the current position to the first element.

    Thanks

    Tuesday, July 5, 2016 8:59 PM

Answers

  • User76916 posted

    @MirkoLonga - Updating the Source of the ListView will cause it to refresh and reset all scroll positions, hence you will have to manually implement it when it refreshes.

    You can look at https://gist.github.com/TheTekton/05ada395a8a12df57c38 to see how someone else did it.

    It basically involves just manually calling the ScrollTo on the ListView to the selected item.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Wednesday, July 6, 2016 1:34 AM

All replies

  • User76916 posted

    @MirkoLonga - Updating the Source of the ListView will cause it to refresh and reset all scroll positions, hence you will have to manually implement it when it refreshes.

    You can look at https://gist.github.com/TheTekton/05ada395a8a12df57c38 to see how someone else did it.

    It basically involves just manually calling the ScrollTo on the ListView to the selected item.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Wednesday, July 6, 2016 1:34 AM
  • User235482 posted

    @AdamP I tried code which link you posted.....but there is not any class of name "Foo" or not code for class "Foo" .... so can you add that method....i am looking exactly same which you posted....thanks in advance:)

    Tuesday, September 20, 2016 7:02 AM
  • User76916 posted

    @AmitG - there is no class called Foo, it is just an example to what your class would be called. For example if you had a list of Animal e.g. List you would replace Foo with Animal.

    Tuesday, September 20, 2016 10:11 AM
  • User233224 posted

    @AdamP there is no way to do it without ScrollTo?

    For example, on WhatsApp, when we scroll the listview top, it loads old messages, but the listview maintain the same position, withou scrolling it.

    Tuesday, March 14, 2017 9:04 PM
  • User31385 posted

    If you bind a ObservableCollection<T> to your ListView's ItemsSource, you can just insert / delete elements in the collection and the ListView will insert / delete cells on screen to match. Depending on what gets inserted / deleted there may be a small amount of scrolling necessary but if the inserted / delete cell is visible on screen that should be pretty minimal.

    Tuesday, March 14, 2017 10:05 PM