A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.
Hi @tim , and thanks for posting your question.
I reproduced the reported behavior in a minimal .NET MAUI project using a ListView, five sample items, and the same SourceCache<FilterList, string> delete logic.
The command parameter is arriving correctly. SelectedObj is successfully cast to FilterList, so CommandParameter="{Binding .}" is working as intended. No change to the ListView, command binding, or CommandParameter is required.
The problem is this line:
_sourceCache.Remove(_trees);
_trees represents the entire collection bound to the ListView. Passing it to Remove removes all items contained in that collection from _sourceCache. This is why clicking Delete on one row clears the entire list.
Reproduced behavior before the fix:
ListView empty after clicking Delete on one item
Fix
Remove the FilterList item already obtained from the command parameter:
public void OnDeleteCommandAction(object SelectedObj)
{
try
{
if (SelectedObj is FilterList filterList)
{
_sourceCache.Remove(filterList);
}
}
catch (Exception ex)
{
Console.WriteLine("iOS Delete Exception: {0}", ex);
}
}
The minimal required change is:
// Before: removes all items in the displayed collection
_sourceCache.Remove(_trees);
// After: removes only the item passed to the command
_sourceCache.Remove(filterList);
After applying this change in the reproduction project, clicking Delete removed only the selected row while the remaining items stayed in the ListView.
Result after applying the fix
ListView showing only the selected item removed
Therefore, the behavior can be resolved within the code provided. The root cause is passing the entire _trees collection to Remove instead of passing the selected filterList item.
If this instruction is applicable to your situation, I would greatly appreciate it if you could follow the instruction here so others experiencing similar behavior can benefit from it as well.