使用Xamarin表单创建Multiselect Listview(Xamarin跨平台)

使用Xamarin表单创建Multiselect Listview(Xamarin跨平台)

问题描述:

我试图在Listview的每个项目中实现一个带有Checkbox控件的Listview.如果要删除两个项目,我将检查这两个项目并单击Delete将其删除.还能在Github中找到单个演示示例.

I am trying to implement a Listview with Checkbox controll in each item of Listview.If I want to delete two items I will check those two items and click of delete it should delete.I explored more about this kind of concept but not able to find single demo example in Github as well.

编程语言:Xamarin表单不在Xamarin android或Xamain IOS中.我已经知道如何在这些平台上实现.但是我至少没有任何示例代码,以便更好地理解"Xamarin表单中的多选和删除操作"

Programming Language:Xamarin forms not in Xamarin android or Xamain IOS.I already know how to implement in those platforms.But I dont have any sample code at least to for better understanding of "Multiselect and deletion operation in Xamarin Forms"

  • 使用SwitchCell(此处的示例: https://github.com/xamarin/xamarin-forms-samples/tree/master/UserInterface/ListView/SwitchEntryTwoBinding/twoWayBinding ))
    • Use SwitchCell (example here: https://github.com/xamarin/xamarin-forms-samples/tree/master/UserInterface/ListView/SwitchEntryTwoBinding/twoWayBinding))
    • 或创建自定义ViewCell布局( https://developer.xamarin.com/guides/cross-platform/xamarin-forms/user-interface/listview/customizing-cell-appearance/-自定义单元格 >章节)

      or create custom ViewCell layout (https://developer.xamarin.com/guides/cross-platform/xamarin-forms/user-interface/listview/customizing-cell-appearance/ - Custom Cells chapter)

      • 使用您的ViewModel.ObservableCollection.IsChecked属性绑定SwitchCell.OnPropertyYourCustomViewCell.Checkbox.CheckedProperty(如SwitchEntryTwoBinding示例)

      • Bind SwitchCell.OnProperty or YourCustomViewCell.Checkbox.CheckedProperty with your ViewModel.ObservableCollection.IsChecked property (as in SwitchEntryTwoBinding example)

      然后您可以制作一个ButtonToolbarItem,该方法调用对ViewModel.ObservableCollection中的每个项目进行迭代的方法,并在IsChecked=true时将其删除.

      Then you could make a Button or ToolbarItem which calls method that iterates every item in ViewModel.ObservableCollection and deletes it if IsChecked=true.