コード例 #1
0
        private bool VerifyBoundState()
        {
            // If the panel becomes "unbound" while attached to a generator, this
            // method detaches it and makes it really behave like "unbound."  This
            // can happen because of a style change, a theme change, etc. It returns
            // the correct "bound" state, after the dust has settled.
            //
            // This is really a workaround for a more general problem that the panel
            // needs to release resources (an event handler) when it is "out of the tree."
            // Currently, there is no good notification for when this happens.

            bool isItemsHost = (ItemsControl.GetItemsOwnerInternal(this) != null);

            if (isItemsHost)
            {
                if (_itemContainerGenerator == null)
                {
                    // Transitioning from being unbound to bound
                    ClearChildren();
                }

                return(_itemContainerGenerator != null);
            }
            else
            {
                if (_itemContainerGenerator != null)
                {
                    // Transitioning from being bound to unbound
                    DisconnectFromGenerator();
                    ClearChildren();
                }

                return(false);
            }
        }
コード例 #2
0
        /// <summary>Indicates that the <see cref="P:System.Windows.Controls.Panel.IsItemsHost" /> property value has changed.</summary>
        /// <param name="oldIsItemsHost">The old property value.</param>
        /// <param name="newIsItemsHost">The new property value.</param>
        // Token: 0x060052E7 RID: 21223 RVA: 0x00171508 File Offset: 0x0016F708
        protected virtual void OnIsItemsHostChanged(bool oldIsItemsHost, bool newIsItemsHost)
        {
            DependencyObject itemsOwnerInternal = ItemsControl.GetItemsOwnerInternal(this);
            ItemsControl     itemsControl       = itemsOwnerInternal as ItemsControl;
            Panel            panel = null;

            if (itemsControl != null)
            {
                IItemContainerGenerator itemContainerGenerator = itemsControl.ItemContainerGenerator;
                if (itemContainerGenerator != null && itemContainerGenerator == itemContainerGenerator.GetItemContainerGeneratorForPanel(this))
                {
                    panel = itemsControl.ItemsHost;
                    itemsControl.ItemsHost = this;
                }
            }
            else
            {
                GroupItem groupItem = itemsOwnerInternal as GroupItem;
                if (groupItem != null)
                {
                    IItemContainerGenerator generator = groupItem.Generator;
                    if (generator != null && generator == generator.GetItemContainerGeneratorForPanel(this))
                    {
                        panel = groupItem.ItemsHost;
                        groupItem.ItemsHost = this;
                    }
                }
            }
            if (panel != null && panel != this)
            {
                panel.VerifyBoundState();
            }
            this.VerifyBoundState();
        }
コード例 #3
0
        /// <summary>
        ///     This method is invoked when the IsItemsHost property changes.
        /// </summary>
        /// <param name="oldIsItemsHost">The old value of the IsItemsHost property.</param>
        /// <param name="newIsItemsHost">The new value of the IsItemsHost property.</param>
        protected virtual void OnIsItemsHostChanged(bool oldIsItemsHost, bool newIsItemsHost)
        {
            // GetItemsOwner will check IsItemsHost first, so we don't have
            // to check that IsItemsHost == true before calling it.
            DependencyObject parent       = ItemsControl.GetItemsOwnerInternal(this);
            ItemsControl     itemsControl = parent as ItemsControl;
            Panel            oldItemsHost = null;

            if (itemsControl != null)
            {
                // ItemsHost should be the "root" element which has
                // IsItemsHost = true on it.  In the case of grouping,
                // IsItemsHost is true on all panels which are generating
                // content.  Thus, we care only about the panel which
                // is generating content for the ItemsControl.
                IItemContainerGenerator generator = itemsControl.ItemContainerGenerator as IItemContainerGenerator;
                if (generator != null && generator == generator.GetItemContainerGeneratorForPanel(this))
                {
                    oldItemsHost           = itemsControl.ItemsHost;
                    itemsControl.ItemsHost = this;
                }
            }
            else
            {
                GroupItem groupItem = parent as GroupItem;
                if (groupItem != null)
                {
                    IItemContainerGenerator generator = groupItem.Generator as IItemContainerGenerator;
                    if (generator != null && generator == generator.GetItemContainerGeneratorForPanel(this))
                    {
                        oldItemsHost        = groupItem.ItemsHost;
                        groupItem.ItemsHost = this;
                    }
                }
            }

            if (oldItemsHost != null && oldItemsHost != this)
            {
                // when changing ItemsHost panels, disconnect the old one
                oldItemsHost.VerifyBoundState();
            }

            VerifyBoundState();
        }
コード例 #4
0
        // Token: 0x060052FD RID: 21245 RVA: 0x001716D4 File Offset: 0x0016F8D4
        private bool VerifyBoundState()
        {
            bool flag = ItemsControl.GetItemsOwnerInternal(this) != null;

            if (flag)
            {
                if (this._itemContainerGenerator == null)
                {
                    this.ClearChildren();
                }
                return(this._itemContainerGenerator != null);
            }
            if (this._itemContainerGenerator != null)
            {
                this.DisconnectFromGenerator();
                this.ClearChildren();
            }
            return(false);
        }