I’m trying to remove some objects from a ListBox that I have created, and for some reason ListBox.Items.IsReadOnly is true.
The following calls don’t work:
myListBox.Items.Add("whatever")
myListBox.Items.Add("stuff")
myListBox.Items.Remove("whatever")
I get an exception:
{System.InvalidOperationException: Operation not supported on read-only collection.
at System.Windows.Controls.ItemCollection.RemoveImpl(Object value)
at System.Windows.Controls.ItemCollection.RemoveInternal(Object value)
at System.Windows.PresentationFrameworkCollection`1.Remove(T value)
I can set ListBox.ItemsSource, but working with .Items is much easier. I’m creating the ListBox like this:
let mutable myListBox= new ListBox()
Any ideas/suggestions would be greatly appreciated. Thanks.
I’m not sure of the F# syntax, but you should be setting the ListBox.ItemsSource.
If you create an
ObservableCollectionand then set that to theItemsSourceyou can add and remove items from the collection and the list box will update automatically.