只读集合不支持操作

编程入门 行业动态 更新时间:2024-10-14 16:23:29
本文介绍了只读集合不支持操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我有一个ListBox,其中每行由Image和TextBlock组成。当我删除一行后面的代码,如:

this.UserListBox.Items.RemoveAt(this.UserListBox.SelectedIndex) ;

它会抛出一个例外:

只读集合中不支持操作。

如何从列表框中删除行?

我在写一个Windows Phone 7 APP。

解决方案

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

I have a ListBox with rows where each row consist of an "Image" and a "TextBlock". When I delete one row in the back with code like:

this.UserListBox.Items.RemoveAt(this.UserListBox.SelectedIndex);

There it throws an exception:

Operation not supported on read-only collection.

How can I delete row from the listbox?

I am writing a Windows phone 7 APP.

解决方案

If you set ItemsSource on the ListBox, then Items is internally generated and readonly. In such case you need to delete the item from the supoplied item collection. If the collection implements INotifyCollectionChanged, then the collection changes are reflected in the listbox.

更多推荐

只读集合不支持操作

本文发布于:2023-11-12 10:55:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1581290.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不支持   操作

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!