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

Time:01-03

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();
    }

CodePudding user response:

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.

  • Related