2015-08-21 71 views
1

我想在Listview的每个项目中使用复选框controll实现Listview。如果我想删除两个项目,我将检查这两个项目并单击删除它应该删除。我对这种概念进行了更多的探索,但也无法在Github中找到单个演示示例。我不知道如何实现这些平台。但我没有任何示例代码,至少为了更好地理解“Xamarin Forms中的多选和删除操作”使用Xamarin Forms创建多选列表(Xamarin跨平台)

+0

我假设你已经浏览了所有[Xamarin.Forms示例](https://github.com/xamarin/xamarin-forms-samples)? – rubenvb

+0

您是否尝试过在您的列表视图中使用自定义单元格? – germi

回答

4

或者创建自定义ViewCell布局(https://developer.xamarin.com/guides/cross-platform/xamarin-forms/user-interface/listview/customizing-cell-appearance/ - 定制单元章)

  • 绑定SwitchCell.OnPropertyYourCustomViewCell.Checkbox.CheckedPropertyViewModel.ObservableCollection.IsChecked财产(如SwitchEntryTwoBinding为例)

  • 然后,你可以做一个ButtonToolbarItem它调用的方法,在ViewModel.ObservableCollection遍历每个项目并删除它,如果IsChecked=true

+0

这里是我的代码,当我点击删除按钮时,项目中的行必须从列表视图[Xamarin Forms]中删除。 – user3783920

0

首先使用开关创建自定义单元格(或者执行SwitchCell)。然后将交换机的值绑定到数据模型中的bool。然后,在按钮点击事件上,一个简单的Linq查询应该可以做到。

请确保您的项目列表是ObservableCollection,因此当您删除项目时,更改会正确传播到ListView。

0

我们在这里创建了一个Multi Select ListView控件。它适用于所有平台,并且没有平台特定的代码。 https://github.com/MelbourneDeveloper/Adapt.Presentation/blob/master/Adapt.Presentation.Standard/Adapt/Presentation/Controls/AdaptListView.cs

这里有包括一个完整的示例: https://github.com/MelbourneDeveloper/Adapt.Presentation.git

这工作得很好,异步的行为。即您可以按任意顺序设置ItemsSource或SelectedItems。有一个在回购多选样本: https://github.com/MelbourneDeveloper/Adapt.Presentation.git

还有用按钮切换选择模式,使您可以在列表视图跳下来选定的记录,或选择多条记录行为: https://github.com/MelbourneDeveloper/Adapt.Presentation/blob/master/Adapt.Presentation.Standard/Adapt/Presentation/Behaviours/AdaptListViewSelectionModeToggleBehavior.cs

此行为是相关的,因为它可以让你从一个ListView删除选定的项目: https://github.com/MelbourneDeveloper/Adapt.Presentation/blob/master/Adapt.Presentation.Standard/Adapt/Presentation/Behaviours/RemoveFromCollectionBehavior.cs

不幸的是,这个目前不支持的CheckBox,但该功能可以运行,而无需复选框和我们可以在futu中添加该功能回覆。