Ejemplo n.º 1
0
        /// <summary>
        /// Synchronizes changes of srcList, applying them to destList.
        /// Changes are described in args.
        /// </summary>
        public static void ApplyChanges(IList destList, IList srcList, ListChangedEventArgs args)
        {
            switch (args.Type)
            {
            case ListChangedEventType.ItemsInserted: {
                for (int i = 0; i < args.Count; i++)
                {
                    destList.Insert(args.Index + i, srcList[args.Index + i]);
                }
                break;
            }

            case ListChangedEventType.ItemsRemoved:
                for (int i = 0; i < args.Count; i++)
                {
                    destList.RemoveAt(args.Index);
                }
                break;

            case ListChangedEventType.ItemReplaced: {
                destList[args.Index] = srcList[args.Index];
                break;
            }
            }
        }
Ejemplo n.º 2
0
        private void ItemsOnListChanged(object sender, ListChangedEventArgs args)
        {
            switch (args.Type)
            {
            case ListChangedEventType.ItemsInserted: {
                for (int i = 0; i < args.Count; i++)
                {
                    onItemInserted(i + args.Index);
                }
                break;
            }

            case ListChangedEventType.ItemsRemoved: {
                foreach (TreeItem treeItem in args.RemovedItems.Cast <TreeItem>())
                {
                    onItemRemoved(treeItem);
                }
                break;
            }

            case ListChangedEventType.ItemReplaced: {
                onItemRemoved((TreeItem)args.RemovedItems[0]);
                onItemInserted(args.Index);
                break;
            }
            }
        }
            private void onListChanged(object sender, ListChangedEventArgs args) {
                switch (args.Type) {
                    case ListChangedEventType.ItemsInserted: {
                        for (int i = 0; i < args.Count; i++) {
                            var control = (Control) list[args.Index + i];
                            parent.InsertChildAt(args.Index + i, control);
                            if (ControlAdded != null) ControlAdded.Invoke(control);
                        }
                        break;
                    }
                    case ListChangedEventType.ItemsRemoved:
                        for (int i = 0; i < args.Count; i++) {
                            Control control = parent.Children[args.Index];
                            parent.RemoveChild(control);
                            if (ControlRemoved != null) ControlRemoved.Invoke(control);
                        }
                        break;
                    case ListChangedEventType.ItemReplaced: {
                        var removedControl = parent.Children[args.Index];
                        parent.RemoveChild(removedControl);
                        if (ControlRemoved != null) ControlRemoved.Invoke(removedControl);

                        var addedControl = (Control) list[args.Index];
                        parent.InsertChildAt(args.Index, addedControl);
                        if (ControlAdded != null) ControlAdded.Invoke(addedControl);
                        break;
                    }
                }
            }
Ejemplo n.º 4
0
        private void targetListChanged(object sender, ListChangedEventArgs args)
        {
            // To avoid side effects from old listeners
            // (can be reproduced if call raisePropertyChanged inside another ObservableList handler)
            // propertyChanged will cause re-subscription to ListChanged, but
            // old list still can call ListChanged when enumerates event handlers
            if (!ReferenceEquals(sender, targetList))
            {
                return;
            }

            ignoreSourceListener = true;
            try {
                ApplyChanges(sourceList, targetList, args);
            } finally {
                ignoreSourceListener = false;
            }
        }
Ejemplo n.º 5
0
 private void ItemsOnListChanged(object sender, ListChangedEventArgs args) {
     switch (args.Type) {
         case ListChangedEventType.ItemsInserted: {
             for (int i = 0; i < args.Count; i++)
                 onItemInserted(i + args.Index);
             break;
         }
         case ListChangedEventType.ItemsRemoved: {
             foreach (TreeItem treeItem in args.RemovedItems.Cast<TreeItem>())
                 onItemRemoved(treeItem);
             break;
         }
         case ListChangedEventType.ItemReplaced: {
             onItemRemoved((TreeItem) args.RemovedItems[0]);
             onItemInserted(args.Index);
             break;
         }
     }
 }
Ejemplo n.º 6
0
        private void targetListChanged(object sender, ListChangedEventArgs args) {
            // To avoid side effects from old listeners
            // (can be reproduced if call raisePropertyChanged inside another ObservableList handler)
            // propertyChanged will cause re-subscription to ListChanged, but
            // old list still can call ListChanged when enumerates event handlers
            if (!ReferenceEquals(sender, targetList)) return;

            ignoreSourceListener = true;
            try {
                ApplyChanges(sourceList, targetList, args);
            } finally {
                ignoreSourceListener = false;
            }
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Synchronizes changes of srcList, applying them to destList.
 /// Changes are described in args.
 /// </summary>
 public static void ApplyChanges(IList destList, IList srcList, ListChangedEventArgs args) {
     switch (args.Type) {
         case ListChangedEventType.ItemsInserted: {
             for (int i = 0; i < args.Count; i++) {
                 destList.Insert(args.Index + i, srcList[args.Index + i]);
             }
             break;
         }
         case ListChangedEventType.ItemsRemoved:
             for (int i = 0; i < args.Count; i++)
                 destList.RemoveAt(args.Index);
             break;
         case ListChangedEventType.ItemReplaced: {
             destList[args.Index] = srcList[args.Index];
             break;
         }
     }
 }