Ejemplo n.º 1
0
        void ScenarioViewModel_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            switch (e.Action)
            {
            case System.Collections.Specialized.NotifyCollectionChangedAction.Add:
                for (int i = e.NewStartingIndex; i < e.NewStartingIndex + e.NewItems.Count; i++)
                {
                    this[i].OwnerScenario = this;
                    Model.Insert(i, this[i].Model);
                }
                break;

            case System.Collections.Specialized.NotifyCollectionChangedAction.Replace:
                for (int i = e.NewStartingIndex; i < e.NewStartingIndex + e.NewItems.Count; i++)
                {
                    this[i].OwnerScenario = this;
                    Model[i] = this[i].Model;
                }
                break;

            case System.Collections.Specialized.NotifyCollectionChangedAction.Remove:
                foreach (AtomViewModel atom in e.OldItems)
                {
                    atom.OwnerScenario = null;
                    Model.RemoveAt(e.OldStartingIndex);

                    if (OwnerDocument != null)
                    {
                        OwnerDocument.ClearLinks(atom);
                    }
                }

                IsComplex = Items.Any(atom => atom.Model.Type == AtomTypes.Marker);
                break;

            case System.Collections.Specialized.NotifyCollectionChangedAction.Reset:
                Model.Clear();
                foreach (AtomViewModel atom in this)
                {
                    atom.OwnerScenario = this;
                    Model.Add(atom.Model);
                }

                IsComplex = Items.Any(atom => atom.Model.Type == AtomTypes.Marker);
                break;
            }

            UpdateCommands();
        }