如何使用下方的点击功能删除列表视图中的所有内容? 现在它只删除列表中的第一个项目而不是每个项目。 这是我的代码:
async void OnButtonClickedRemoveEverything (object sender, EventArgs args)
{
theGuestListMembers ourItem = null; //theGuestListMembers is our Class.
foreach (theGuestListMembers c in ourEventList) { //oureventlist = this is Our List.
ourItem = c;
}
// listID是一个公共字符串,用于获取个人信息" info"来自用户(objectID)。所以我想" ourItem.listID"是我们的问题,因为我只得到1人对象ID我猜不是列表中的所有人吗?
if(ourItem != null)
{
parseAPI.deleteTheGuestList
(Application.Current.Properties ["sessionToken"].ToString (), ourItem.listID);
ourEventList.Remove (ourItem);
EmployeeList.ItemsSource = null; //name of our list
EmployeeList.ItemsSource = ourEventList;
}
Navigation.PopAsync ();
}
我获取信息的数据库。
var getItems = await parseAPI.getOurGuestList (Application.Current.Properties ["sessionToken"].ToString (), owner);
EmployeeList.ItemsSource = null;
ourEventList = new List<theGuestListMembers> ();
foreach (var currentItem in getItems["results"]) {
ourEventList.Add (new theGuestListMembers () {
listID = currentItem ["objectId"].ToString (),
theHeadName = currentItem ["YourName"].ToString ()
});
}
答案 0 :(得分:2)
如果您只想删除列表中的项目,可以使用ourEventList.Clear()
或ourEventList.RemoveAll(ourItem => ourItem != null)
如果你想做更好的事情,你可以使用这个功能:
private bool removeItem(theGuestListMember ourItem)
{
if (ourItem == null) return false;
parseAPI.deleteTheGuestList(ourItem);
return true;
}
并像这样使用它:
async private void OnButtonClickedRemoveEverything(object sender, EventArgs e)
{
ourEventList.RemoveAll(ourItem => removeItem(ourItem);
EmployeeList.ItemsSource = ourEventList;
Navigation.PopAsync ();
}