加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

windows-phone-7 – 如何从Windows 7手机上的列表框中删除项目?

发布时间:2020-12-14 01:42:18 所属栏目:Windows 来源:网络整理
导读:我使用ItemsSource,当我想从列表中删除一个项目时,我收到一个错误. 错误: 只读集合不支持操作. MenuItem menuItem = (MenuItem) sender; MessageBox.Show(menuItem.Header.ToString(),"Result",MessageBoxButton.OK); ListBoxItem lb (ListBoxItem)listBoxJ
我使用ItemsSource,当我想从列表中删除一个项目时,我收到一个错误.
错误:
只读集合不支持操作.
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上得到了错误.
谢谢

如果在ListBox上设置ItemsSource,则Items在内部生成并且是只读的.
因此,在这种情况下,您需要从supoplied项集合中删除该项.
如果集合实现了INotifyCollectionChanged,则集合更改将反映在列表框中.

ObservableCollection是一个实现INotifyCollectionChanged的列表

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读