Beispiel #1
0
        /// <summary>
        /// Internal method called when the control is removed from a rooted logical tree.
        /// </summary>
        /// <param name="e">The event args.</param>
        private void OnDetachedFromLogicalTreeCore(LogicalTreeAttachmentEventArgs e)
        {
            if (_isAttachedToLogicalTree)
            {
                if (Name != null)
                {
                    _nameScope?.Unregister(Name);
                }

                _isAttachedToLogicalTree = false;
                _styleDetach.OnNext(this);
                OnDetachedFromLogicalTree(e);

                foreach (var child in LogicalChildren.OfType <Control>())
                {
                    child.OnDetachedFromLogicalTreeCore(e);
                }

#if DEBUG
                if (((INotifyCollectionChangedDebug)_classes).GetCollectionChangedSubscribers()?.Length > 0)
                {
                    Logger.Warning(
                        LogArea.Control,
                        this,
                        "{Type} detached from logical tree but still has class listeners",
                        this.GetType());
                }
#endif
            }
        }
Beispiel #2
0
        /// <summary>
        /// Called when the control is removed from a logical tree.
        /// </summary>
        /// <param name="e">The event args.</param>
        /// <remarks>
        /// It is vital that if you override this method you call the base implementation;
        /// failing to do so will cause numerous features to not work as expected.
        /// </remarks>
        protected virtual void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e)
        {
            if (Name != null)
            {
                _nameScope?.Unregister(Name);
            }

            _isAttachedToLogicalTree = false;
            _styleDetach.OnNext(Unit.Default);
            this.TemplatedParent = null;
            DetachedFromLogicalTree?.Invoke(this, e);

            foreach (var child in LogicalChildren.OfType <Control>())
            {
                child.OnDetachedFromLogicalTree(e);
            }
        }