Exemplo n.º 1
0
        /// <summary>
        /// Synchronizes the logical tree.
        /// </summary>
        /// <param name="e">The <see cref="System.Collections.Specialized.NotifyCollectionChangedEventArgs" /> instance containing the event data.</param>
        private void SyncLogicalTree(NotifyCollectionChangedEventArgs e)
        {
            // In order to get DataContext and binding to work with the series, axes and annotations
            // we add the items to the logical tree
            if (e.NewItems != null)
            {
                foreach (var item in e.NewItems.OfType <ISetLogicalParent>())
                {
                    item.SetParent(this);
                }
                LogicalChildren.AddRange(e.NewItems.OfType <ILogical>());
                VisualChildren.AddRange(e.NewItems.OfType <IVisual>());
            }

            if (e.OldItems != null)
            {
                foreach (var item in e.OldItems.OfType <ISetLogicalParent>())
                {
                    item.SetParent(null);
                }
                foreach (var item in e.OldItems)
                {
                    LogicalChildren.Remove((ILogical)item);
                    VisualChildren.Remove((IVisual)item);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Called when the <see cref="Children"/> collection changes.
        /// </summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event args.</param>
        protected virtual void ChildrenChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            List <Control> controls;

            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
                controls = e.NewItems.OfType <Control>().ToList();
                LogicalChildren.InsertRange(e.NewStartingIndex, controls);
                VisualChildren.AddRange(e.NewItems.OfType <Visual>());
                break;

            case NotifyCollectionChangedAction.Move:
                LogicalChildren.MoveRange(e.OldStartingIndex, e.OldItems.Count, e.NewStartingIndex);
                VisualChildren.MoveRange(e.OldStartingIndex, e.OldItems.Count, e.NewStartingIndex);
                break;

            case NotifyCollectionChangedAction.Remove:
                controls = e.OldItems.OfType <Control>().ToList();
                LogicalChildren.RemoveAll(controls);
                VisualChildren.RemoveAll(e.OldItems.OfType <Visual>());
                break;

            case NotifyCollectionChangedAction.Replace:
                for (var i = 0; i < e.OldItems.Count; ++i)
                {
                    var index = i + e.OldStartingIndex;
                    var child = (IControl)e.NewItems[i];
                    LogicalChildren[index] = child;
                    VisualChildren[index]  = child;
                }
                break;

            case NotifyCollectionChangedAction.Reset:
                throw new NotSupportedException();
            }

            InvalidateMeasure();
        }
Exemplo n.º 3
0
 public void AddChildren(IEnumerable <Visual> v)
 {
     VisualChildren.AddRange(v);
 }