问题
I am working on windows phone app and I want to delete item from listbox.
I am using following code List numbers=new List();
ObservableCollection<string> myCollection = new ObservableCollection<string>(numbers);
int indexPerson = listBox1.SelectedIndex;
myCollection.RemoveAt(indexPerson);
var my = (ObservableCollection<string>)listBox1.ItemsSource;
listBox1.ItemsSource=my;
and when I click on delete button one item is deleted based on index and then when I will delete another item the previously deleted item is show and current deleted item is deleted.
How can I delete all items?
回答1:
If you want to clear all items you can just use
myCollection.ClearItems()
if you want to remove just selected item than use
myCollection.Remove(Listbox1.Selecteditem)
来源:https://stackoverflow.com/questions/30567951/how-to-delete-item-from-observable-collection-in-c-sharp