I am using observable collections all around my applications. My problem is that when i use a popup window for editing those entities, my bound lists are getting changed when the user changes those corresponding fields in the window.
How could i simply freeze the observable changes norifications, and release them only when the entity is saved?
Thanks, Oran
I think the issue is not with the collection, but with the entities themselves. ObservableCollection
raises an event when an item is added or removed, not when a property of an item is changed. This part is handled by the INotifyPropertyChanged
implemented by the item, so it's this notification you need to disable.
I suggest you have a look at the IEditableObject
interface, which is designed for this kind of scenario. You can disable the notifications in the BeginEdit
method, and reenable them in EndEdit
and CancelEdit
.
EDIT: Paul Stovell has a nice implementation of an IEditableObject
wrapper here :
http://www.paulstovell.com/editable-object-adapter
You can use:
BoundPropertyOfViewModel = CollectionViewSource.GetDefaultView(AgentDeploymentDetail);
and bind to the view instead of binding directly to the ObservableCollection. This is the same object that allow you to filter/sort your output without touching the collection.
When you want to stop changes, use DeferRefresh()
. When you are done, call Refresh()
.
WARNING
This will not pervent showing of changes in each item itself, only the list.
You could make a deep copy of the object you want to edit. This way, you can act on the copy while editing, without interfering with the original that remains in the list. Once you`re done editing, you can replace the original by the edited version or rollback.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With