Exemplo n.º 1
0
 // Token: 0x06005307 RID: 21255 RVA: 0x001718C8 File Offset: 0x0016FAC8
 private void OnItemsChanged(object sender, ItemsChangedEventArgs args)
 {
     if (this.VerifyBoundState())
     {
         bool flag = this.OnItemsChangedInternal(sender, args);
         if (flag)
         {
             base.InvalidateMeasure();
         }
     }
 }
        // Token: 0x06005A34 RID: 23092 RVA: 0x0018D7B8 File Offset: 0x0018B9B8
        internal override bool OnItemsChangedInternal(object sender, ItemsChangedEventArgs args)
        {
            NotifyCollectionChangedAction action = args.Action;

            if (action > NotifyCollectionChangedAction.Move)
            {
                base.OnItemsChangedInternal(sender, args);
            }
            this.OnItemsChanged(sender, args);
            return(this.ShouldItemsChangeAffectLayout(true, args));
        }
Exemplo n.º 3
0
        void OnItemsChangedInternal(object sender, ItemsChangedEventArgs args)
        {
            InvalidateMeasure();
            if (args.Action == NotifyCollectionChangedAction.Reset)
            {
                Children.Clear();
                ItemContainerGenerator.RemoveAll();
                OnClearChildren();
            }

            OnItemsChanged(sender, args);
        }
Exemplo n.º 4
0
 /// <summary>
 /// When items are removed, remove the corresponding UI if necessary
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="args"></param>
 protected override void OnItemsChanged(object sender, ItemsChangedEventArgs args)
 {
     switch (args.Action)
     {
         case NotifyCollectionChangedAction.Remove:
         case NotifyCollectionChangedAction.Replace:
             RemoveInternalChildRange(args.Position.Index, args.ItemUICount);
             break;
         case NotifyCollectionChangedAction.Move:
             RemoveInternalChildRange(args.OldPosition.Index, args.ItemUICount);
             break;
     }
 }
Exemplo n.º 5
0
        private void OnItemsChanged(object sender, ItemsChangedEventArgs args)
        {
            if (VerifyBoundState())
            {
                Debug.Assert(_itemContainerGenerator != null, "Encountered a null _itemContainerGenerator while receiving an ItemsChanged from a generator.");

                bool affectsLayout = OnItemsChangedInternal(sender, args);

                if (affectsLayout)
                {
                    InvalidateMeasure();
                }
            }
        }
Exemplo n.º 6
0
        // This method returns a bool to indicate if or not the panel layout is affected by this collection change
        internal override bool OnItemsChangedInternal(object sender, ItemsChangedEventArgs args)
        {
            switch (args.Action)
            {
            case NotifyCollectionChangedAction.Add:
            case NotifyCollectionChangedAction.Remove:
            case NotifyCollectionChangedAction.Replace:
            case NotifyCollectionChangedAction.Move:
                // Don't allow Panel's code to run for add/remove/replace/move
                break;

            default:
                base.OnItemsChangedInternal(sender, args);
                break;
            }

            OnItemsChanged(sender, args);

            return(ShouldItemsChangeAffectLayout(true /*areItemChangesLocal*/, args));
        }
Exemplo n.º 7
0
        // This method returns a bool to indicate if or not the panel layout is affected by this collection change
        internal virtual bool OnItemsChangedInternal(object sender, ItemsChangedEventArgs args)
        {
            switch (args.Action)
            {
                case NotifyCollectionChangedAction.Add:
                    AddChildren(args.Position, args.ItemCount);
                    break;
                case NotifyCollectionChangedAction.Remove:
                    RemoveChildren(args.Position, args.ItemUICount);
                    break;
                case NotifyCollectionChangedAction.Replace:
                    ReplaceChildren(args.Position, args.ItemCount, args.ItemUICount);
                    break;
                case NotifyCollectionChangedAction.Move:
                    MoveChildren(args.OldPosition, args.Position, args.ItemUICount);
                    break;

                case NotifyCollectionChangedAction.Reset:
                    ResetChildren();
                    break;
            }

            return true;
        }
Exemplo n.º 8
0
        protected override void OnItemsChanged(object sender, ItemsChangedEventArgs args)
        {
            base.OnItemsChanged(sender, args);
            IItemContainerGenerator generator = ItemContainerGenerator;
            ItemsControl            owner = ItemsControl.GetItemsOwner(this);
            int index, offset, viewable;

            switch (args.Action)
            {
            case NotifyCollectionChangedAction.Add:
                // The following logic is meant to keep the current viewable items in view
                // after adjusting for added items.
                index = generator.IndexFromGeneratorPosition(args.Position);
                if (Orientation == Orientation.Horizontal)
                {
                    offset = (int)HorizontalOffset;
                }
                else
                {
                    offset = (int)VerticalOffset;
                }

                if (index <= offset)
                {
                    // items have been added earlier in the list than what is viewable
                    offset += args.ItemCount;
                }

                if (Orientation == Orientation.Horizontal)
                {
                    SetHorizontalOffset(offset);
                }
                else
                {
                    SetVerticalOffset(offset);
                }
                break;

            case NotifyCollectionChangedAction.Remove:
                // The following logic is meant to keep the current viewable items in view
                // after adjusting for removed items.
                index = generator.IndexFromGeneratorPosition(args.Position);
                if (Orientation == Orientation.Horizontal)
                {
                    offset   = (int)HorizontalOffset;
                    viewable = (int)ViewportWidth;
                }
                else
                {
                    viewable = (int)ViewportHeight;
                    offset   = (int)VerticalOffset;
                }

                if (index < offset)
                {
                    // items earlier in the list than what is viewable have been removed
                    offset = Math.Max(offset - args.ItemCount, 0);
                }

                // adjust for items removed in the current view and/or beyond the current view
                offset = Math.Min(offset, owner.Items.Count - viewable);
                offset = Math.Max(offset, 0);

                if (Orientation == Orientation.Horizontal)
                {
                    SetHorizontalOffset(offset);
                }
                else
                {
                    SetVerticalOffset(offset);
                }

                RemoveInternalChildRange(args.Position.Index, args.ItemUICount);
                break;

            case NotifyCollectionChangedAction.Replace:
                RemoveInternalChildRange(args.Position.Index, args.ItemUICount);
                break;

            case NotifyCollectionChangedAction.Reset:
                // DO NOTHING
                break;
            }

            InvalidateMeasure();

            if (ScrollOwner != null)
            {
                ScrollOwner.InvalidateScrollInfo();
            }
        }
Exemplo n.º 9
0
 /// <summary>
 ///     Returns whether an Items collection change affects layout for this panel.
 /// </summary>
 /// <param name="args">Event arguments</param>
 /// <param name="areItemChangesLocal">Says if this notification represents a direct change to this Panel's collection</param>
 protected virtual bool ShouldItemsChangeAffectLayoutCore(bool areItemChangesLocal, ItemsChangedEventArgs args)
 {
     return(true);
 }
Exemplo n.º 10
0
 public bool ShouldItemsChangeAffectLayout(bool areItemChangesLocal, ItemsChangedEventArgs args)
 {
     return(ShouldItemsChangeAffectLayoutCore(areItemChangesLocal, args));
 }
Exemplo n.º 11
0
 /// <summary>
 ///     Called when the Items collection associated with the containing ItemsControl changes.
 /// </summary>
 /// <param name="sender">sender</param>
 /// <param name="args">Event arguments</param>
 protected virtual void OnItemsChanged(object sender, ItemsChangedEventArgs args)
 {
 }
Exemplo n.º 12
0
        protected virtual void OnGeneratorItemsChanged(object sender, ItemsChangedEventArgs e)
        {
            if (e.Action == NotifyCollectionChangedAction.Add)
            {
                for (int i = 0; i < e.ItemsCount; i++)
                {
                    Children.Insert(i + e.NewStartingIndex, ItemContainerGenerator.Generate(i + e.NewStartingIndex));
                }
            }

            if (e.Action == NotifyCollectionChangedAction.Remove)
            {
                Children.RemoveRange(e.OldStartingIndex, e.ContainersCount);
            }

            if (e.Action == NotifyCollectionChangedAction.Move)
            {
                IEnumerable<UIElement> movedChildren = Children.Skip(e.OldStartingIndex).Take(e.ContainersCount);

                Children.RemoveRange(e.OldStartingIndex, e.ContainersCount);
                Children.InsertRange(e.NewStartingIndex, movedChildren);
            }

            if (e.Action == NotifyCollectionChangedAction.Replace)
            {
                Children[e.NewStartingIndex] = ItemContainerGenerator.Generate(e.NewStartingIndex);
            }

            if (e.Action == NotifyCollectionChangedAction.Reset)
            {
                Children.Clear();
                AddChildren();
            }
        }
Exemplo n.º 13
0
        protected override sealed void OnItemsChanged(object sender, ItemsChangedEventArgs args)
        {
            if (args == null)
            {
                throw new ArgumentNullException("args");
            }

            var owner = ItemsOwner;
            var items = owner != null ? owner.Items : null;

            var action = args.Action;

            if (action == NotifyCollectionChangedAction.Reset)
            {
                OnItemsChanged(items, new NotifyCollectionChangedEventArgs(action));
            }
            else if (items != null)
            {
                var generator = sender as IItemContainerGenerator;
                if (generator != null)
                {
                    if (action == NotifyCollectionChangedAction.Add)
                    {
                        var index = generator.IndexFromGeneratorPosition(args.Position);
                        // ItemContainerGenerator is infested with bugs. One of which is that as items are added to the end of a collection, the index from IndexFromGeneratorPosition will usually be wrong.
                        if (args.Position.Offset == 1)
                        {
                            index = items.Count - 1;
                        }
                        var newItems = new VirtualItemsList(items, index, args.ItemCount);

                        if (!IsVirtualizing)
                        {
                            for (int i = index; i < index + args.ItemCount; i++)
                            {
                                RealizeItem(i);
                            }
                        }

                        OnItemsChanged(items, new NotifyCollectionChangedEventArgs(action, newItems, index));
                    }
                    else if (action == NotifyCollectionChangedAction.Remove)
                    {
                        var oldIndex = generator.IndexFromGeneratorPosition(args.Position);
                        var oldItems = new ArrayList(args.ItemCount);

                        // Since we can't actually get the old items directly, and sometimes we can't even get the old index from the generator, we'll get as many as we can from the visuals.
                        for (int i = 0; i < args.ItemUICount; i++)
                        {
                            var element = InternalChildren[args.Position.Index + i];
                            oldItems.Add(ItemFromContainer(element));
                            if (oldIndex == -1)
                            {
                                oldIndex = (int)element.ReadLocalValue(IndexForItemContainerProperty);
                            }
                            element.ClearValue(IndexForItemContainerProperty);
                        }

                        // Unfortunately ItemContainerGenerator always expects us to remove the child, even if we didn't want to.
                        if (args.ItemUICount > 0)
                        {
                            RemoveInternalChildRange(args.Position.Index, args.ItemUICount);
                        }

                        OnItemsChanged(items, new NotifyCollectionChangedEventArgs(action, oldItems, oldIndex));
                    }
                    else if (action == NotifyCollectionChangedAction.Move)
                    {
                        var oldIndex   = -1;
                        var index      = generator.IndexFromGeneratorPosition(args.Position);
                        var movedItems = new VirtualItemsList(items, index, args.ItemCount);

                        var count = args.ItemUICount;
                        if (count > 0)
                        {
                            var elements = new UIElement[count];
                            for (var i = 0; i < count; i++)
                            {
                                elements[i] = InternalChildren[args.OldPosition.Index + i];
                                if (oldIndex == -1)
                                {
                                    oldIndex = (int)elements[i].ReadLocalValue(IndexForItemContainerProperty);
                                }
                            }
                            RemoveInternalChildRange(args.OldPosition.Index + Math.Min(args.OldPosition.Offset, 1), count);
                            for (var i = 0; i < count; i++)
                            {
                                InsertInternalChild(args.Position.Index + i, elements[i]);
                            }
                        }

                        OnItemsChanged(items, new NotifyCollectionChangedEventArgs(action, movedItems, index, oldIndex));
                    }
                    else if (action == NotifyCollectionChangedAction.Replace)
                    {
                        var index    = generator.IndexFromGeneratorPosition(args.Position);
                        var newItems = new VirtualItemsList(items, index, args.ItemCount);
                        // Todo: Actually get the old items.  ItemContainerGenerator doesn't make this easy.
                        var oldItems = new VirtualItemsList(null, index, args.ItemCount);

                        OnItemsChanged(items, new NotifyCollectionChangedEventArgs(action, newItems, oldItems, index));
                    }
                }
            }

            base.OnItemsChanged(sender, args);

            InvalidateReality();
        }
Exemplo n.º 14
0
        internal void OnOwnerItemsItemsChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            int itemCount;
            int itemUICount;
            GeneratorPosition oldPosition = new GeneratorPosition(-1, 0);
            GeneratorPosition position;

            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
                if ((e.NewStartingIndex + 1) != Owner.Items.Count)
                {
                    MoveExistingItems(e.NewStartingIndex, 1);
                }
                itemCount   = 1;
                itemUICount = 0;
                position    = GeneratorPositionFromIndex(e.NewStartingIndex);
                // Yes, this looks like a Silverlight Bug.
                position.Offset = 1;
                break;

            case NotifyCollectionChangedAction.Remove:
                itemCount   = 1;
                itemUICount = RealizedElements.Contains(e.OldStartingIndex) ? 1 : 0;
                position    = GeneratorPositionFromIndex(e.OldStartingIndex);
                if (itemUICount == 1)
                {
                    Remove(position, 1);
                }
                MoveExistingItems(e.OldStartingIndex, -1);
                break;

            case NotifyCollectionChangedAction.Replace:
                if (!RealizedElements.Contains(e.NewStartingIndex))
                {
                    return;
                }

                itemCount   = 1;
                itemUICount = 1;
                position    = GeneratorPositionFromIndex(e.NewStartingIndex);
                Remove(position, 1);

                bool fresh;
                var  newPos = GeneratorPositionFromIndex(e.NewStartingIndex);
                using (StartAt(newPos, GeneratorDirection.Forward, true))
                    PrepareItemContainer(GenerateNext(out fresh));
                break;

            case NotifyCollectionChangedAction.Reset:
                itemCount   = e.OldItems == null ? 0 : e.OldItems.Count;
                itemUICount = RealizedElements.Count;
                position    = new GeneratorPosition(-1, 0);
                RemoveAll();
                break;

            default:
                Console.WriteLine("*** Critical error in ItemContainerGenerator.OnOwnerItemsItemsChanged. NotifyCollectionChangedAction.{0} is not supported", e.Action);
                return;
            }

            ItemsChangedEventArgs args = new ItemsChangedEventArgs {
                Action      = e.Action,
                ItemCount   = itemCount,
                ItemUICount = itemUICount,
                OldPosition = oldPosition,
                Position    = position
            };
            var h = ItemsChanged;

            if (h != null)
            {
                h(this, args);
            }
        }
Exemplo n.º 15
0
        protected sealed override void OnItemsChanged(object sender, ItemsChangedEventArgs args)
        {
            if (args == null)
            {
                throw new ArgumentNullException("args");
            }
            ItemCollection itemCollection        = ItemsOwner?.Items;
            NotifyCollectionChangedAction action = args.Action;

            if (action == NotifyCollectionChangedAction.Reset)
            {
                OnItemsChanged(itemCollection, new NotifyCollectionChangedEventArgs(action));
            }
            else if (itemCollection != null)
            {
                IItemContainerGenerator itemContainerGenerator = sender as IItemContainerGenerator;
                if (itemContainerGenerator != null)
                {
                    switch (action)
                    {
                    case NotifyCollectionChangedAction.Add:
                    {
                        int num4 = itemContainerGenerator.IndexFromGeneratorPosition(args.Position);
                        if (args.Position.Offset == 1)
                        {
                            num4 = itemCollection.Count - 1;
                        }
                        VirtualItemsList changedItems2 = new VirtualItemsList(itemCollection, num4, args.ItemCount);
                        if (!IsVirtualizing)
                        {
                            for (int k = num4; k < num4 + args.ItemCount; k++)
                            {
                                RealizeItem(k);
                            }
                        }
                        OnItemsChanged(itemCollection, new NotifyCollectionChangedEventArgs(action, changedItems2, num4));
                        break;
                    }

                    case NotifyCollectionChangedAction.Remove:
                    {
                        int       num5      = itemContainerGenerator.IndexFromGeneratorPosition(args.Position);
                        ArrayList arrayList = new ArrayList(args.ItemCount);
                        for (int l = 0; l < args.ItemUICount; l++)
                        {
                            UIElement uIElement = base.InternalChildren[args.Position.Index + l];
                            arrayList.Add(ItemFromContainer(uIElement));
                            if (num5 == -1)
                            {
                                num5 = (int)uIElement.ReadLocalValue(IndexForItemContainerProperty);
                            }
                            uIElement.ClearValue(IndexForItemContainerProperty);
                        }
                        if (args.ItemUICount > 0)
                        {
                            RemoveInternalChildRange(args.Position.Index, args.ItemUICount);
                        }
                        OnItemsChanged(itemCollection, new NotifyCollectionChangedEventArgs(action, arrayList, num5));
                        break;
                    }

                    case NotifyCollectionChangedAction.Move:
                    {
                        int num2 = -1;
                        int num3 = itemContainerGenerator.IndexFromGeneratorPosition(args.Position);
                        VirtualItemsList changedItems = new VirtualItemsList(itemCollection, num3, args.ItemCount);
                        int itemUICount = args.ItemUICount;
                        if (itemUICount > 0)
                        {
                            UIElement[] array = new UIElement[itemUICount];
                            for (int i = 0; i < itemUICount; i++)
                            {
                                array[i] = base.InternalChildren[args.OldPosition.Index + i];
                                if (num2 == -1)
                                {
                                    num2 = (int)array[i].ReadLocalValue(IndexForItemContainerProperty);
                                }
                            }
                            RemoveInternalChildRange(args.OldPosition.Index + Math.Min(args.OldPosition.Offset, 1), itemUICount);
                            for (int j = 0; j < itemUICount; j++)
                            {
                                InsertInternalChild(args.Position.Index + j, array[j]);
                            }
                        }
                        OnItemsChanged(itemCollection, new NotifyCollectionChangedEventArgs(action, changedItems, num3, num2));
                        break;
                    }

                    case NotifyCollectionChangedAction.Replace:
                    {
                        int num = itemContainerGenerator.IndexFromGeneratorPosition(args.Position);
                        VirtualItemsList newItems = new VirtualItemsList(itemCollection, num, args.ItemCount);
                        VirtualItemsList oldItems = new VirtualItemsList(null, num, args.ItemCount);
                        OnItemsChanged(itemCollection, new NotifyCollectionChangedEventArgs(action, newItems, oldItems, num));
                        break;
                    }
                    }
                }
            }
            base.OnItemsChanged(sender, args);
            InvalidateReality();
        }