windows phone 8 -如何在c#中删除Observable集合中的Item

本文关键字:删除 Observable 集合 Item phone windows | 更新日期: 2023-09-27 17:51:23

我正在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;

当我点击删除按钮时,一个项目根据索引被删除,然后当我要删除另一个项目时,先前删除的项目显示,当前删除的项目被删除。

如何删除所有项?

windows phone 8 -如何在c#中删除Observable集合中的Item

如果你想清除所有项目,你可以使用

myCollection.ClearItems()

如果你想删除选中的项目,使用

 myCollection.Remove(Listbox1.Selecteditem)