dotnet / dotnet/maui

CollectionView is not updating SelectedItems bound property

Open
#8,435 37 comments 5 reactions 1 assignee Assigned to @karthikraja-arumugam View on GitHub
area-controls-collectionview delighter platform/android platform/windows s/needs-attention s/triaged s/verified t/bug
Dominant language
C#
Stars
23.3k
Forks
2k
Avg merge
1d 15h
Merged PRs (30d)
290

Description

### Description

With multiselection for a CollectionView, the bound property for SelectedItems is always null in my viewModel. It works fine for single selection where SelectedItem bound property does get set correctly. I see the same problem in my real all and in James Montemagno's Maui full course. It also shows in a very simple attached app.
My main problem is that without this property getting updated, I don't know how to clear selected items from my view model. The selected items do get passed to the SelectedItemChanged command handler (as can be seen in the attached sample) but I have not found a way to use that to clear 1 or all selected items. In my real app, I need to delete the selected items and hence remove the selection. I can remove them from the collection but the CollectionView still keeps the selected items and the selected item count
[CollectionViewTest1.zip](https://github.com/dotnet/maui/files/9017765/CollectionViewTest1.zip)
.

### Steps to Reproduce

Unzip and run the attached CollectionViewTest1 as a Windows app. I see the same problem in Android.
You will see a collection view with a list of fruits
Select 1 or more fruits and the output console will show (eg)

Count of selected fruits in parameter = 1
bound property SelectedFruits is NULL

or set a breakpoint in FruitViewModel FruitSelectionChanged to see where these messages come from.
The problem is that SelectedFruits is null

I have seen this in windows and Android but have not tried other platforms.

### Version with bug

6.0.400 (current)

### Last version that worked well

Unknown/Other

### Affected platforms

Android, Windows

### Affected platform versions

Windows 11 and Android 11

### Did you find any workaround?

No workaround was found but I am a beginner! I would at least like a workaround so I can clear the selected items from my view model.
Thank you.

### Relevant log output

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.