MVVM .net MAUI delete button not working

What I'm trying to do is: 1. Click the delete button 2. The deleted item gets removed from the collectionview However, this is not working with the code that I have, as it gives me this error or crashes the program. I followed stackoverflow on similar issues, such as this one: https://stackoverflow.com/questions/74460587/how-to-delete-selected-item-from-collection-view-in-net-maui, just without the selection I've set my command binding to the delete command in the view model, and the problem starts occurring when I set my commandparameter's binding to . or Items, is there a fix for my problem? what is the problem that occurred in my logic?
Stack Overflow
How to delete selected Item from collection view in .net MAUI
I have collection in my Child view. <CollectionView SelectionMode="Single" SelectedItem="{Binding Source={Reference sideview}, Path=myViewModel.SelectedItem.FileName}" ...
No description
2 Replies
CreamofSumYungGai
this is my delete command:
[ICommand]
private async void Delete(string s)
{
// Fix the delete command not working
if (Items.Contains(s))
{
Console.WriteLine($"{s} has been deleted!");
Items.Remove(s);
}
//removes the item from the MainPage's viewmodel
}
[ICommand]
private async void Delete(string s)
{
// Fix the delete command not working
if (Items.Contains(s))
{
Console.WriteLine($"{s} has been deleted!");
Items.Remove(s);
}
//removes the item from the MainPage's viewmodel
}
and my binding command is set to this:
Command="{Binding DeleteCommand, Source={RelativeSource AncestorType={x:Type viewmodel:MainViewModel}}}"
CommandParameter="{Binding .}"
Command="{Binding DeleteCommand, Source={RelativeSource AncestorType={x:Type viewmodel:MainViewModel}}}"
CommandParameter="{Binding .}"
CreamofSumYungGai
GitHub
GitHub - Morganiscooler/Notepad-Bugged-with-breakpoint-: A randomly...
A randomly generated code keeps popping up and will not let me use the app anymore - Morganiscooler/Notepad-Bugged-with-breakpoint-