使用Xamarin表单创建Multiselect Listview(Xamarin跨平台) [英] Create Multiselect Listview with Xamarin Forms(Xamarin Cross Platform)
问题描述
我试图在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)) -
使用您的
ViewModel.ObservableCollection.IsChecked
属性绑定SwitchCell.OnProperty
或YourCustomViewCell.Checkbox.CheckedProperty
(如SwitchEntryTwoBinding示例) Bind
SwitchCell.OnProperty
orYourCustomViewCell.Checkbox.CheckedProperty
with yourViewModel.ObservableCollection.IsChecked
property (as in SwitchEntryTwoBinding example)
或创建自定义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)
然后您可以制作一个Button
或ToolbarItem
,该方法调用对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
.
这篇关于使用Xamarin表单创建Multiselect Listview(Xamarin跨平台)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!