Xamarin Forms CollectionView Select 所有项目

Xamarin Forms CollectionView Select All Items

我正在使用多平台 Xamarin 表单,我希望能够单击一个按钮并 select collectionview.

中的所有项目

我有:

<CollectionView x:Name="collectionList" SelectionMode="Multiple"
                            SelectionChanged="RowSelected"
                            ItemsSource="{Binding ContentList}">

在cs文件中:

ObservableCollection ContentList = //list made in an earlier method, this is confirmed working
collectionList.SelectedItems= ContentList; //executes on the button click event

但是这不起作用,因为 SelectedItems 需要一个 IList,它不接受正常的 ListObservableCollection。我还尝试将 SelectedItems 设置为 collectionList.ItemsSource (collectionview 源代码),但这给出了相同的类型错误,即 Cannot implicitly convert type 'System.Collections.Generic.List<object>' to 'System.Collections.Generic.IList<object>'

我目前的工作是 collectionview 填充数据,用户可以手动 select 编辑多个项目。这个 returns 我被点击的项目。不过,我无法以编程方式查看 select 所有内容。

我搜索了所有内容,但没有看到任何帖子尝试这样做,为集合视图制作“select 全部”按钮的最佳方法是什么?

编辑:问题是我的列表有一个定义的 class 作为列表类型,它需要是 object 类型,如下面接受的答案中所列

我刚试过这个并且有效

collectionList.SelectedItems = new ObservableCollection<object>(ContentList);

毫无疑问还有其他方法,但不是我在周日下午能想到的