I'm using a observable collection in my program to store "years". User can "Add" or "Remove" years from the collection. So "years" will be listed on ListBox. Window has "OK" and "Cancel". If user click "Cancel" button after entering years, I want to undo that changes and get back to original state, so user will see Original Observable Collection without any changes in next time he try to enter. Changes should only apply when click "OK" button. I implemented "OK" button correctly. What I want is to undo changes if click "cancel" button. Hope this is clear.
public RelayCommand Cancel
{
get
{
return _cancel
?? (_cancel = new RelayCommand(
() =>
{
foreach (var change in ChangesList)
{
switch (change.Action)
{
case NotifyCollectionChangedAction.Add:
// What I have to do here
break;
case NotifyCollectionChangedAction.Remove:
// What I have to do here.
break;
}
}
Messenger.Default.Send(new NotificationMessage("Cancel"));
}));
}
}
Here is my cancel relay command. I have get changes that have made to the Original Observable collection into a "ChangeList". What I want is to undo those changes when click on "cancel" button.