this is in regards to the tutorial on msdn. This is whats used to close workspaces or tabs.
// workspaces declared as follows
_workspaces = new ObservableCollection<WorkspaceViewModel>();
_workspaces.CollectionChanged += this.OnWorkspacesChanged;
void OnWorkspacesChanged(object sender, NotifyCollectionChangedEventArgs e)
{
if (e.NewItems != null && e.NewItems.Count != 0)
foreach (WorkspaceViewModel workspace in e.NewItems)
workspace.RequestClose += this.OnWorkspaceRequestClose;
if (e.OldItems != null && e.OldItems.Count != 0)
foreach (WorkspaceViewModel workspace in e.OldItems)
workspace.RequestClose -= this.OnWorkspaceRequestClose;
}
What i don't understand is what will e.NewItems
and e.OldItems
be. Assuming NewItems
will be the new item thats added into the collection, I attach the event handler? But then it will be singular, since I add 1 item at a time usually? then if it means all the items that will still exists after the change, why will I need to re-attach the event handlers?