コード例 #1
0
        private void LayersChanged(object sender, NotifyCollectionChangedEventArgs args)
        {
            switch (args.Action)
            {
            case NotifyCollectionChangedAction.Add:
                foreach (ILayer layer in args.NewItems)
                {
                    ILayerListNodeViewModel entry = LayerListMethods.Generate(this.eventAggregator, this.session, this.actionHandler, layer);
                    int insertIndex = args.NewStartingIndex;
                    if (insertIndex < this.LayerNodes.Count)
                    {
                        this.LayerNodes.Insert(insertIndex++, entry);
                    }
                    else
                    {
                        this.LayerNodes.Add(entry);
                    }
                }
                break;

            case NotifyCollectionChangedAction.Remove:
                foreach (ILayer layer in args.OldItems)
                {
                    IEnumerable <ILayerListNodeViewModel> toRemove = new ObservableCollection <ILayerListNodeViewModel>(this.LayerNodes.Where(entry => entry.Layer == layer));
                    foreach (ILayerListNodeViewModel entry in toRemove)
                    {
                        this.LayerNodes.Remove(entry);
                    }
                }
                break;

            case NotifyCollectionChangedAction.Move:
                int oldIndex = args.OldStartingIndex;
                int newIndex = args.NewStartingIndex;
                if (oldIndex != -1 && newIndex != -1)
                {
                    ILayerListNodeViewModel entry = this.LayerNodes[oldIndex];
                    this.LayerNodes[oldIndex] = this.LayerNodes[newIndex];
                    this.LayerNodes[newIndex] = entry;
                }
                break;

            default:
                break;
            }
        }
コード例 #2
0
        private void UpdateLayers(object sender, NotifyCollectionChangedEventArgs e)
        {
            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
                foreach (ILayer layer in e.NewItems)
                {
                    ILayerListNodeViewModel entry = LayerListMethods.Generate(this.eventAggregator, this.Session, this.actionHandler, layer);
                    int insertIndex = e.NewStartingIndex;
                    if (insertIndex < this.LayerNodes.Count)
                    {
                        this.LayerNodes.Insert(insertIndex++, entry);
                    }
                    else
                    {
                        this.LayerNodes.Add(entry);
                    }
                }
                break;

            case NotifyCollectionChangedAction.Remove:
                foreach (ILayer layer in e.OldItems)
                {
                    ILayerListNodeViewModel toRemove = this.LayerNodes.FirstOrDefault(entry => entry.Layer == layer);
                    this.LayerNodes.Remove(toRemove);
                }
                break;

            case NotifyCollectionChangedAction.Move:
                int oldIndex = e.OldStartingIndex;
                int newIndex = e.NewStartingIndex;
                if (oldIndex != -1 && newIndex != -1)
                {
                    ILayerListNodeViewModel entry = this.LayerNodes[oldIndex];
                    this.LayerNodes[oldIndex] = this.LayerNodes[newIndex];
                    this.LayerNodes[newIndex] = entry;
                }
                break;

            default:
                break;
            }
        }
コード例 #3
0
        private void LoadLayers(ObservableCollection <ILayer> layers)
        {
            this.LayerNodes.Clear();
            if (layers == null)
            {
                return;
            }

            foreach (ILayer layer in layers)
            {
                ILayerListNodeViewModel node = LayerListMethods.Generate(this.eventAggregator, this.Session, this.actionHandler, layer);
                this.LayerNodes.Add(node);

                if (this.Session.CurrentLayer.Value == layer)
                {
                    node.IsSelected.Value = true;
                    this.selectedNode     = node;
                }
            }
        }