我正在windows phone应用程序上工作,我想从列表框中删除项目。
我正在使用以下代码List number =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;
当我点击删除按钮时,一个项目根据索引被删除,然后当我要删除另一个项目时,先前删除的项目显示,当前删除的项目被删除。
如何删除所有项?
如果你想清除所有项目,你可以使用
myCollection.ClearItems()
如果你想删除选中的项目,使用
myCollection.Remove(Listbox1.Selecteditem)