private void Editor_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { if (e.NewItems != null && e.NewItems.Count > 0) { foreach (object o in e.NewItems) { if (o is PageViewModel) { PageViewModel page = (PageViewModel)o; RegisterPage(page); WindowMenuItems.Add(new MenuItemViewModel(this, page.ProjectItem.Name, page.SelectPageCommand) { Identifier = page.Identifier }); } } } if (e.OldItems != null && e.OldItems.Count > 0) { foreach (object o in e.OldItems) { if (o is PageViewModel) { PageViewModel page = (PageViewModel)o; UnregisterPage(page); foreach (MenuItemViewModel item in WindowMenuItems) { if (item.Identifier == page.Identifier) { WindowMenuItems.Remove(item); break; } } } } } }