Refresh UI Dotnet Maui

Viewed 59

I have a collection view with a list of items and inside of the data template i have the following: Viewmodel:

[ObservableProperty]
ObservableCollection<InfoService> services;

Xaml:

<CollectionView ItemsSource="{Binding Services}"
                            VerticalOptions="Start"
                            ItemsLayout="VerticalGrid">
                <CollectionView.ItemTemplate>
                    <DataTemplate x:DataType="dto:InfoService">
                        <Grid RowDefinitions="Auto,Auto,Auto,Auto" ColumnDefinitions="Auto,Auto,Auto">
                            <Label Grid.Row="0" Grid.Column="0" Text="{Binding serviceName}" FontSize="Medium"/>
                            <Label Grid.Column="0" Grid.Row="2">
                                <Label.FormattedText>
                                    <FormattedString>
                                        <Span Text="Barcode: " FontSize="Micro" TextColor="LightGray"/>
                                        <Span Text="{Binding barcode}" FontSize="Micro" TextColor="LightGray"/>
                                    </FormattedString>
                                </Label.FormattedText>
                            </Label>
                            
                        <ImageButton Source="trash.png"
                                     Grid.Column="2" 
                                     Grid.Row="1"
                                     Command="{Binding Source={RelativeSource AncestorType={x:Type viewmodel:myViewModel}},Path=DeleteServiceCommand}"
                                     CommandParameter="{Binding .}" />
                        </Grid>
                    </DataTemplate>
                </CollectionView.ItemTemplate>
            </CollectionView>

Command:

[RelayCommand]
void DeleteService(InfoService service)
{
    Services.Remove(service);          
    GetTotal();
}

The items get deleted but the ui still have the item. Also i want to know if there is a proper way to refresh the ui in similar cases.

Already tried:

  • mainThread InvokeOnMainThread

  • ObservableCollection // List

Also if someone can provide an explanation, could be useful for other user since i think could be a common case

0 Answers
Related