コード例 #1
0
        /// <summary>
        /// Sets the specified TItem at the specified index;
        /// Connects the item to the model tree;
        /// Notifies the TItem about the event.
        /// </summary>
        /// <exception cref="ArgumentException">
        /// If the new item has already a parent or if the slot at the specified index is not null.
        /// </exception>
        /// <remarks>
        /// Note that the function requires that _item[index] == null and
        /// it also requires that the passed in item is not included into another ContentElementCollection.
        /// </remarks>
        internal override void PrivateConnectChild(int index, TableColumn item)
        {
            Debug.Assert(item != null && item.Index == -1);
            Debug.Assert(Items[index] == null);

            // If the TItem is already parented correctly through a proxy, there's no need
            // to change parentage.  Otherwise, it should be parented to Owner.
            if (item.Parent is DummyProxy)
            {
                if (LogicalTreeHelper.GetParent(item.Parent) != Owner)
                {
                    throw new System.ArgumentException(SR.Get(SRID.TableCollectionWrongProxyParent));
                }
            }
            else
            {
                if (item.Parent != null)
                {
                    throw new System.ArgumentException(SR.Get(SRID.TableCollectionInOtherCollection));
                }

                Owner.AddLogicalChild(item);
            }

            // add the item into collection's array
            Items[index] = item;
            item.Index   = index;

            // notify the TItem about the change
            item.OnEnterParentTree();
        }