Hello I hope you can help me.
I have a RadListView that gets populated from a collection provided in the ViewModel. Within the template there is a button to delete the selected element and it works fine, but when there is only one element left and I delete it, the application crashes.
The xaml of the list
<telerik:RadListView ItemsSource="{Binding SelectedProducts, Mode=TwoWay}" SelectionMode="None" >
<telerik:RadListView.ItemTemplate>
<DataTemplate x:DataType="modles:ProductExhibitionDTO">
<telerik:ListViewTemplateCell>
<telerik:ListViewTemplateCell.View>
<Grid BackgroundColor="#FAFAFA" RowDefinitions="auto, auto, *, auto, auto, auto">
<Grid Grid.Row="0" ColumnDefinitions="auto, *, auto">
<Label Grid.Column="0" Text="{Binding ProductNumber}" Margin="8" FontSize="14" FontFamily="RobotoBold" TextColor="#000" />
<Button Grid.Column="2" HorizontalOptions="End" Margin="8" ImageSource="delete_out_6" HeightRequest="24" WidthRequest="24" Command="{Binding Source={RelativeSource AncestorType={x:Type viewModel:NegotiatedExhibitionViewModel}}, Path=DeleteProductCommand}" CommandParameter="{Binding .}" BackgroundColor="Transparent" />
</Grid>
<Grid Grid.Row="1" RowDefinitions="auto, auto, auto" ColumnDefinitions="auto, 3*, *" >
<Image Grid.Row="0" Grid.RowSpan="3" Grid.Column="0" Source="{Binding ProductImageURL}" HeightRequest="100" WidthRequest="100" Margin="8"/>
<Label Grid.Row="0" Grid.Column="1" VerticalOptions="Start" Margin="8,4" FontSize="12" TextColor="#000" FontFamily="RobotoRegular" Text="{Binding BrandName}" />
<Label Grid.Row="1" Grid.Column="1" VerticalOptions="Start" HorizontalOptions="Fill" Margin="8,4" FontSize="14" TextColor="#000" FontFamily="RobotoBold" Text="{Binding ProductName}" LineBreakMode="WordWrap" />
<Label Grid.Row="2" Grid.Column="1" VerticalOptions="Start" Margin="8,4" FontSize="14" TextColor="#000" FontFamily="RobotoRegular" Text="{Binding GTIN}" />
</Grid>
<Grid Grid.Row="2" ColumnDefinitions=".5*,.5*" RowDefinitions="auto, auto">
<HorizontalStackLayout Grid.Row="0" Grid.Column="0">
<Label Grid.Row="0" Grid.Column="0" TextTransform ="Uppercase" Margin="8" Text="Frentes" TextColor="#757575" FontSize="10" FontFamily="RobotoRegular" />
<Image Source="warning_out" IsVisible="{Binding IsFrontRequired,Mode=TwoWay}" Margin="8" HeightRequest="15" WidthRequest="15"/>
</HorizontalStackLayout>
<HorizontalStackLayout Grid.Row="0" Grid.Column="1">
<Label Grid.Row="0" Grid.Column="1" TextTransform ="Uppercase" Margin="8" Text="Fondos" TextColor="#757575" FontSize="10" FontFamily="RobotoRegular"/>
<Image Source="warning_out" IsVisible="{Binding IsFundRequired,Mode=TwoWay}" Margin="8" HeightRequest="15" WidthRequest="15"/>
</HorizontalStackLayout>
<telerik:RadBorder Grid.Row="1" Grid.Column="0" Margin="8,4">
<telerik:RadEntry Text="{Binding Front}" Keyboard="Numeric" BackgroundColor="#FFFFFF" FontSize="14" FontFamily="RobotoRegular" WidthRequest="80" HorizontalOptions="Start" ClearButtonVisibility="Never" FocusedBorderBrush="Transparent" IsReadOnly="{Binding IsReadOnly}" />
</telerik:RadBorder>
<telerik:RadBorder Grid.Row="1" Grid.Column="1" Margin="8,4" >
<telerik:RadEntry Text="{Binding Fund}" Keyboard="Numeric" BackgroundColor="#FFFFFF" FontSize="14" FontFamily="RobotoRegular" WidthRequest="80" HorizontalOptions="Start" ClearButtonVisibility="Never" FocusedBorderBrush="Transparent" IsReadOnly="{Binding IsReadOnly}" />
</telerik:RadBorder>
</Grid>
</Grid>
</telerik:ListViewTemplateCell.View>
</telerik:ListViewTemplateCell>
</DataTemplate>
</telerik:RadListView.ItemTemplate>
</telerik:RadListView>
The DeleteItem command in the viewModel,
[RelayCommand]
void DeleteProduct(Object obj) //ProductExhibitionDTO productExhibitionDTO
{
ProductExhibitionDTO productExhibitionDTO = obj as ProductExhibitionDTO;
if (productExhibitionDTO != null)
{
SelectedProducts.Remove(productExhibitionDTO);
}
}
And finally, the error:
This happens more commonly when I have already written values in the RadEntry that are in the template.