【发布时间】:2020-10-18 22:59:45
【问题描述】:
我正在使用多平台 Xamarin 表单,我希望能够单击一个按钮并选择 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 需要一个不接受普通 List 或 ObservableCollection 的 IList。我还尝试将 SelectedItems 设置为 collectionList.ItemsSource (collectionview 源),但这给出了相同的类型错误,即Cannot implicitly convert type 'System.Collections.Generic.List<object>' to 'System.Collections.Generic.IList<object>'
我目前的工作是collectionview 填充数据,并且用户可以手动选择多个项目。这会返回我被点击的项目。我无法让视图以编程方式选择所有内容。
我已经搜索了所有内容,但没有看到任何尝试这样做的帖子,为收藏视图制作“全选”按钮的最佳方法是什么?
编辑:问题是我的列表有一个定义的类作为列表类型,它需要是object 类型,如下面接受的答案中所列
【问题讨论】:
标签: xamarin xamarin.forms observablecollection collectionview