Windows phone 7 如何在Windows 7 phone上从列表框中删除项目?
我使用ItemsSource,当我想从列表中删除一个项目时,会出现一个错误。 错误: 只读集合上不支持操作Windows phone 7 如何在Windows 7 phone上从列表框中删除项目?,windows-phone-7,Windows Phone 7,我使用ItemsSource,当我想从列表中删除一个项目时,会出现一个错误。 错误: 只读集合上不支持操作 MenuItem menuItem = (MenuItem) sender; MessageBox.Show(menuItem.Header.ToString(), "Result", MessageBoxButton.OK); ListBoxItem lb (ListBoxItem)listBoxJournal.ItemContainer
MenuItem menuItem = (MenuItem) sender;
MessageBox.Show(menuItem.Header.ToString(), "Result", MessageBoxButton.OK);
ListBoxItem lb (ListBoxItem)listBoxJournal.ItemContainerGenerator.ContainerFromItem(((MenuItem)sender).DataContext);
liste.Remove((Note)lb.Content);
listBoxJournal.UpdateLayout();
listBoxJournal.Items.Clear();
listBoxJournal.ItemsSource = liste;
我在items.clear行中得到错误。
谢谢如果您在列表框上设置了ItemsSource,则项目将在内部生成且为只读。 因此,在这种情况下,您需要从supoplied item集合中删除该项。 如果集合实现INotifyCollectionChanged,则集合更改将反映在列表框中 ObservableCollection是一个实现INotifyCollectionChanged的列表使用--Listname.RemoveAt(ListBoxName.SelectedIndex)