我想在Listview的每个项目中使用复选框controll实现Listview。如果我想删除两个项目,我将检查这两个项目并单击删除它应该删除。我对这种概念进行了更多的探索,但也无法在Github中找到单个演示示例。我不知道如何实现这些平台。但我没有任何示例代码,至少为了更好地理解“Xamarin Forms中的多选和删除操作”使用Xamarin Forms创建多选列表(Xamarin跨平台)
回答
- 使用
SwitchCell
(例如这里: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/ - 定制单元章)
绑定
SwitchCell.OnProperty
或YourCustomViewCell.Checkbox.CheckedProperty
与ViewModel.ObservableCollection.IsChecked
财产(如SwitchEntryTwoBinding为例)然后,你可以做一个
Button
或ToolbarItem
它调用的方法,在ViewModel.ObservableCollection
遍历每个项目并删除它,如果IsChecked=true
。
这里是我的代码,当我点击删除按钮时,项目中的行必须从列表视图[Xamarin Forms]中删除。 – user3783920
首先使用开关创建自定义单元格(或者执行SwitchCell
)。然后将交换机的值绑定到数据模型中的bool。然后,在按钮点击事件上,一个简单的Linq查询应该可以做到。
请确保您的项目列表是ObservableCollection
,因此当您删除项目时,更改会正确传播到ListView。
我们在这里创建了一个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中添加该功能回覆。
- 1. Xamarin Forms跨平台持久存储
- 2. Xamarin Forms跨平台BBCode支持
- 3. 跨平台在Xamarin
- 4. XAMARIN:跨平台FontFamily
- 5. 使用xamarin跨平台不能在列表视图中使用xamarin跨平台打印json消息
- 6. 使用Xamarin使用RestSharp跨平台
- 7. Xamarin跨平台双滑块
- 8. Xamarin跨平台项目
- 9. xamarin跨平台加密PCL
- 10. 相机跨平台(xamarin)
- 11. Xamarin跨平台开发.net
- 12. 如何使用xamarin我创建了一个跨平台的库?
- 13. C#xamarin无法使用xamarin跨平台项目
- 14. Xamarin表单跨平台AdMob未呈现
- 15. XAMARIN Forms创建绑定DLL
- 16. 使用Visual Studio2015创建Xamarin Forms项目
- 17. Xamarin Forms Xamarin Android
- 18. Xamarin跨平台iOS应用程序
- 19. Xamarin C#跨平台应用程序
- 20. Xamarin Forms XAML - 无法从URL列表中创建多个图像
- 21. 跨平台列表查看刷入xamarin表格
- 22. Xamarin跨平台证书锁定
- 23. Xamarin跨平台PCL GetStringAsync错误
- 24. Xamarin复制文件跨平台
- 25. 在xamarin跨平台推送通知
- 26. Xamarin跨平台UWP图像丢失
- 27. xamarin,跨平台的声音API播放
- 28. DevDefined.OAuth与Xamarin跨平台项目兼容
- 29. Xamarin跨平台Ninject实现与NullReferenceException
- 30. Xamarin跨平台 - 登录/注册
我假设你已经浏览了所有[Xamarin.Forms示例](https://github.com/xamarin/xamarin-forms-samples)? – rubenvb
您是否尝试过在您的列表视图中使用自定义单元格? – germi