Exemplo n.º 1
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);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Sets the control's logical parent.
        /// </summary>
        /// <param name="parent">The parent.</param>
        void ISetLogicalParent.SetParent(ILogical parent)
        {
            var old = Parent;

            if (parent != old)
            {
                if (old != null && parent != null)
                {
                    throw new InvalidOperationException("The Control already has a parent.");
                }

                if (_isAttachedToLogicalTree)
                {
                    var oldRoot = FindStyleRoot(old);

                    if (oldRoot == null)
                    {
                        throw new PerspexInternalException("Was attached to logical tree but cannot find root.");
                    }

                    var e = new LogicalTreeAttachmentEventArgs(oldRoot);
                    OnDetachedFromLogicalTreeCore(e);
                }

                InheritanceParent = parent as PerspexObject;
                _parent           = (IControl)parent;

                if (_parent is IStyleRoot || _parent?.IsAttachedToLogicalTree == true)
                {
                    var newRoot = FindStyleRoot(this);

                    if (newRoot == null)
                    {
                        throw new PerspexInternalException("Parent is atttached to logical tree but cannot find root.");
                    }

                    var e = new LogicalTreeAttachmentEventArgs(newRoot);
                    OnAttachedToLogicalTreeCore(e);
                }

                RaisePropertyChanged(ParentProperty, old, _parent, BindingPriority.LocalValue);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Called when the control is added to 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 OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
        {
            if (_nameScope == null)
            {
                _nameScope = NameScope.GetNameScope(this) ?? ((Control)Parent)?._nameScope;
            }

            if (Name != null)
            {
                _nameScope?.Register(Name, this);
            }

            _isAttachedToLogicalTree = true;
            PerspexLocator.Current.GetService <IStyler>()?.ApplyStyles(this);
            AttachedToLogicalTree?.Invoke(this, e);

            foreach (var child in LogicalChildren.OfType <Control>())
            {
                child.OnAttachedToLogicalTree(e);
            }
        }
Exemplo n.º 4
0
 protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e)
 {
     base.OnDetachedFromLogicalTree(e);
     ItemContainerGenerator.Clear();
 }
Exemplo n.º 5
0
 /// <inheritdoc/>
 protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
 {
     base.OnAttachedToLogicalTree(e);
     _treeView = this.GetLogicalAncestors().OfType <TreeView>().FirstOrDefault();
 }
Exemplo n.º 6
0
 protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
 {
     base.OnAttachedToLogicalTree(e);
     InvalidateFormattedText();
 }
Exemplo n.º 7
0
 protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e)
 {
     base.OnDetachedFromLogicalTree(e);
     ItemContainerGenerator.Clear();
 }
Exemplo n.º 8
0
 /// <inheritdoc/>
 protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
 {
     base.OnAttachedToLogicalTree(e);
     _treeView = this.GetLogicalAncestors().OfType<TreeView>().FirstOrDefault();
 }
Exemplo n.º 9
0
 /// <summary>
 /// Called when the control is removed from a rooted logical tree.
 /// </summary>
 /// <param name="e">The event args.</param>
 protected virtual void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e)
 {
     DetachedFromLogicalTree?.Invoke(this, e);
 }
Exemplo n.º 10
0
 /// <summary>
 /// Called when the control is added to a rooted logical tree.
 /// </summary>
 /// <param name="e">The event args.</param>
 protected virtual void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
 {
     AttachedToLogicalTree?.Invoke(this, e);
 }
Exemplo n.º 11
0
 /// <inheritdoc/>
 void ILogical.NotifyDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e)
 {
     this.OnDetachedFromLogicalTreeCore(e);
 }
Exemplo n.º 12
0
 /// <inheritdoc/>
 protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
 {
     base.OnAttachedToLogicalTree(e);
     this.UpdateSelectionBoxItem(this.SelectedItem);
 }
Exemplo n.º 13
0
 protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
 {
     base.OnAttachedToLogicalTree(e);
     InvalidateFormattedText();
 }
Exemplo n.º 14
0
 /// <inheritdoc/>
 protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
 {
     base.OnAttachedToLogicalTree(e);
     this.UpdateSelectionBoxItem(this.SelectedItem);
 }