dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.26k stars 1.76k forks source link

CollectionView ItemsUpdatingScrollMode got to top of list #25994

Closed IeuanWalker closed 1 day ago

IeuanWalker commented 2 days ago

Description

Currently the CollectionView ItemsUpdatingScrollMode, has 3 options -

ItemsUpdatingScrollMode

A common use case for CollectionView is searching a collection - Image

And ideally every time the user searches for something you'd want to look at the top results. But currently using ItemsUpdatingScrollMode there is no way to achieve this.

You can see what I mean in the following video. I search for the item at the bottom of the list, I then clear the search, but the scroll position is still stuck at the bottom, and the user has to scroll back up them selves https://github.com/user-attachments/assets/ad8ecd27-921d-4abe-82f6-d92ef0ae8a5b

Public API Changes

ItemsUpdatingScrollMode has a new option GoToStart

Intended Use-Case

see description

IeuanWalker commented 2 days ago

My current workaround -

I have created a DataChanged bool property in the view model, that i toggle whenever the ObservableCollection changes. Then on the page code behind i have a property changed event that triggers a scroll too based on the DataChanged

viewModel.PropertyChanged += async (object? _, PropertyChangedEventArgs e) =>
{
    if(e.PropertyName is null)
    {
        return;
    }

    if(e.PropertyName.Equals(nameof(viewModel.DataChanged)))
    {
        await Task.Delay(100);
        itemCollectionView.ScrollTo(0);
    }
};