On the page of XAML, create a ListBox with x:name as _list1, where each entry in the listbox is ListBoxItem
if (_list1. SelectedItem = = NULL)//returns if the selected item of _list1 is empty
{
Return
}
Else
{
var list = _list1. selecteditems;//get all the selected items of _list1
list<listboxitem> outlist = new list<listboxitem> ();//Create a new collection to store all the ListBoxItem of the ListBox, and then manipulate the collection, Iterate over each item in this set, and if so, delete the item in the _list1.
foreach (ListBoxItem item in list)
{
Outlist.add (item);
}
foreach (ListBoxItem item in outlist)//Avoid removing yourself from the situation, as it involves changes in the dynamic set
{
if (item. Content.tostring ()! = "Attachment form")
_list1. Items.remove (item);
}
}
The overall equivalent of using an intermediate container
If the middle of this collection is not applicable, the collection may change during execution due to dynamic removal, resulting in an abnormal execution
Silverlight, Dynamic Data collection, removing the contents of the dynamic collection itself