あなたのためにINotifyCollectionChangedを実装するObservableCollectionを使用できます。 F#は、このようなものになります。
open System
open System.Collections.ObjectModel
open System.Windows
open System.Windows.Controls
open System.Windows.Threading
[<EntryPoint; STAThread>]
let Main args =
let data = ObservableCollection [0 .. 9]
let list = ListBox(ItemsSource = data)
let win = Window(Content = list, Visibility = Visibility.Visible)
let rnd = Random()
let callback =
EventHandler(fun sender args ->
let idx = rnd.Next(0, 10)
data.[idx] <- rnd.Next(0, 10)
)
let ts = TimeSpan(1000000L)
let dp = DispatcherPriority.Send
let cd = Dispatcher.CurrentDispatcher
let timer = DispatcherTimer(ts, dp, callback, cd) in timer.Start()
let app = Application() in app.Run(win)
を不幸にリフレクターがSystem.Windows.Controls.ItemsControl.OnItemCollectionChanged方法は、それが呼び出された選択を削除することを示しているので、あなたは、このデフォルトの動作を回避する必要があるかもしれません。
また、そのようにINotifyPropertyChangedの実装できます。
open System.ComponentModel
type MyObservable() =
let mutable propval = 0.0
let evt = Event<_,_>()
interface INotifyPropertyChanged with
[<CLIEvent>]
member this.PropertyChanged = evt.Publish
member this.MyProperty
with get() = propval
and set(v) = propval <- v
evt.Trigger(this, PropertyChangedEventArgs("MyProperty"))
実装INotifyCollectionChangedも同様に動作します。最高の幸運
、
ダニー