只读集合不支持操作 [英] Operation not supported on read-only collection
问题描述
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.
这篇关于只读集合不支持操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!