Juan Pablo Gomez
Juan Pablo Gomez

Reputation: 5534

.net maui ListView don't scroll to added item when binded to ObservableCollection

I have a maui ListView binded to ObservableCollection, I expect when I add a new element to the collection my ListView automatically scrolls to that new Item.

But instead my ListView doesn't update itself,

I added a CollectionChanged event on my code behind (trying to achieve this), and make a manually scroll when item added but no when I run

LstItems.ScrollTo(e.NewItems[e.NewItems.Count - 1], ScrollToPosition.End, false);

My ListView goes to the end but it rebuilds all the entire ListView as you can see at Adding New Item to ListView

I tryed changing CachingStrategy to: RecycleElement, RetainElement but same result.

I tryed using ScrollToPosition to MakeVisible But same result.

I tryed setting to false the Animation parameter of ScrollTo But same result.

My questions:

  1. There is a way to make my ListView automatically scrolls to the new added item? If not:
  2. There is a way to manually move to the new added item wihtout the UI effect of rebuild the entire ListView?

Upvotes: 3

Views: 2644

Answers (1)

Jessie Zhang -MSFT
Jessie Zhang -MSFT

Reputation: 13879

You can try to use CollectionView to achieve this.

You can scroll to the last item by using the following code:

mCollectionView.ScrollTo(myViewModel.Items.Count - 1, animate: true);

For more about this, you can check: Scroll to End.

Upvotes: 2

Related Questions