I'm currently using an observable collection to store my data objects for a ListView. Adding new objects to the collection works just fine, and the listView updates properly. However when I try to change one of the properties of an object in the collection the listView will not update properly. For example, I have an observable collection DataCollection. I try
_DataCollections.ElementAt(count).Status = "Active";
I perform this change before a long operation due to a button press. The listView will not reflect the change. So I addmyListView.Items.Refresh()
;. This works, however the listView does not get refreshed till button_click method is complete, which is no good by then.
For example:
button1_Click(...)
{
_DataCollections.ElementAt(count).Status = "Active";
myListView.Items.Refresh();
ExecuteLongOperation();
_DataCollections.ElementAt(count).Status = "Finished";
myListView.Items.Refresh();
}
The status will never goto "Active", it will go straight to "Finished" after the method completes. I also tried using a dispatcher like this:
button1_Click(...)
{
this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Background,
(NoArgDelegate)delegate { _DataCollection.ElementAt(count).Status = "Active"; myListView.Items.Refresh(); });
ExecuteLongOperation();
this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Background,
(NoArgDelegate)delegate { _DataCollection.ElementAt(count).Status = "Finished"; myListView.Items.Refresh(); });
}
However, that does not seem to work correctly either. Any tips or ideas would be appreciated.