I spent a few too many hours fiddling with Xamarin Form’s collection view and multi-selection binding. That was somewhat frustrating so I’m writing a little about it in the hopes that you don’t have to deal with the same.
If you have a view like this:
and a View Model like this:
You’d expect the binding to work, right? No problems. Well, no. It doesn’t. The CollectionView will only bind SelectedItems to collections of object
. I don’t know why the Xamarin team decided to go that route, but it is a quirk that has wasted too many hours. While the view example above is correct, the View Model should look like this:
There is some info about this problem in this GitHub issue. Also, the quirk is expected to be fixed in .net5 as shown in this open PR.
Cheers, Lucas