MAUI: Issue with deleteing the last item from ObservableCollection

Sreejith Sreenivasan 1,001 Reputation points
2024-03-15T10:40:04.7333333+00:00

I am using an ObservableCollection saving comments. When I delete a comment, I will fetch the deleted comment id and delete that comment from the ObservableCollection.

My Problem is if I delete the last comment all the previous comments are vanishing from the UI and showing only the initial comment. When I reopen the page or delete any other comment the vanished previous comments are coming back.

My Code:

foreach (var item in customerCommentList)
{
	if (item.parentComment.supportItemComments.commentId == deleteCommentId)
	{
		customerCommentList.Remove(item);
		break;
	}
}

Here customerCommentList is the collection and from that I removing the data. Is there any issue in deleting an item from the collection? Is there any known issue in net 7.0?

Screen recorder video uploaded here and here to understand the issue.

I have created a demo project and added the same logic on it and on demo it is working fine. But on the main project this logic breaks, demo is uploaded here.

Developer technologies | .NET | .NET MAUI
{count} votes

Accepted answer
  1. Anonymous
    2024-04-01T06:54:46.43+00:00

    Please add CachingStrategy="RecycleElementAndDataTemplate" in the <ListView>. This issue is related to listview recycle policy. For more details, please see ListView cache data

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.