public ObservableCollection<string> Names { get; set; }
public ViewModel()
{
names = new ObservableCollection<string>();
Names.CollectionChanged += this.OnCollectionChanged;
}
void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
//Get the sender observable collection
ObservableCollection<string> obsSender = sender as ObservableCollection<string>;
List<string> editedOrRemovedItems = new List<string>();
foreach(string newItem in e.NewItems)
{
editedOrRemovedItems.Add(newItem);
}
foreach(string oldItem in e.OldItems)
{
editedOrRemovedItems.Add(oldItem);
}
//Get the action which raised the collection changed event
NotifyCollectionChangedAction action = e.Action;
}
For more information about the NotificationCollectionChangedEventArgs look here。
EDIT:由于你需要一份附加/搬走的项目清单,我修改了样本代码。