I have collection which is bounded to datagrid in WPF UI.
My requirement is like i have to update the the value of a property 10 times a second for every item in collection.
So i have taken ConcurrentBag type collection. After updating the value for every item. I am firing RaisePropertyChange explicitly. But UI is not changing.
private void timer_Elapsed(object sender, ElapsedEventArgs e)
{
if (stockCollection != null)
{
stockCollection.ToList().ForEach((s) => s.Price = DateTime.Now.Millisecond);
Action raiseStockCollectionProperty = new Action(() => RaisePropertyChangedEvent("StockCollection"));
Dispatcher.BeginInvoke(raiseStockCollectionProperty);
}
}
I don't think that the previous answer will provide a solution to your issue. You are in fact not updating the collection at all: You are updating a property of all the Stock instances in the collection. Updating the collection means adding or removing items in it. As the semantics are different, it's possible that the bound control won't check the properties of already existing objects in the collection when you fire a CollectionChanged event. It would be a sensible optimization.
I would suggest you to implement INotifyPropertyChange in your Stock class, and to fire the propertyChanged event here (on the good thread however, using Dispatcher) in the Price property setter.