Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you dynamically update a collection view in .net maui?

Tags:

c#

.net

maui

I have a test app im working with and im populating the collection view with a sqlite DB. But whenever I use a swipe view to delete the item from the database it works fine but the view never removes the item from the collection view unless the entire view is reloaded. I've tried a few different things, but nothing has any effect, Any recommendations? Would the OnAppearing life cycle cause any issues?

 <Grid BackgroundColor="White">
        <StackLayout Margin="20">
            <CollectionView x:Name="data"
                            SelectionMode="Single"
                            SelectionChanged="ItemSelected"
                            HeightRequest="750"
                            VerticalScrollBarVisibility="Never">

protected override async void OnAppearing()
    {
        base.OnAppearing();
        TodoItemDatabase database = await TodoItemDatabase.Instance;
        data.ItemsSource = await database.GetItemsAsync();
    }
like image 728
JakenBake Avatar asked Sep 11 '25 18:09

JakenBake


1 Answers

From the docs

If the CollectionView is required to refresh as items are added, removed, or changed in the underlying collection, the underlying collection should be an IEnumerable collection that sends property change notifications, such as ObservableCollection.

like image 193
Jason Avatar answered Sep 13 '25 08:09

Jason