私が作成したListBoxからいくつかのオブジェクトを削除しようとしています。何らかの理由でListBox.Items.IsReadOnlyがtrueです。なぜListBox.Items.IsReadOnly = trueですか? (F#/ Silverlight)
次の呼び出しでは動作しません:
myListBox.Items.Add("whatever")
myListBox.Items.Add("stuff")
myListBox.Items.Remove("whatever")
私は例外を取得:
{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)
私はListBox.ItemsSourceを設定しますが、.Itemsでの作業は非常に簡単であることができます。私はListBoxを次のように作成しています:
let mutable myListBox= new ListBox()
アイデアや提案をいただければ幸いです。ありがとう。
私はそれを試みます...それは奇妙です、C#Items.Remove/Items.RemoveAtがうまくいくようだからです:http://stackoverflow.com/questions/1400091/search-and-remove-item-from-リストボックス –
@Mike - それは奇妙だと約束しましたが、私はF#でそれほどよく知られていないので、それがなぜ違うのかを言うことができません。 – ChrisF
新しいObservableCollectionを作成し、それをListBoxのItemsSourceとして割り当て、次にItemsの代わりにそのオブジェクトを操作することで、これが機能します。なぜアイテムが読み込み専用であるのかまだ分かりませんが、ちょっと、これはうまくいきます。ありがとう。 –