/// <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) { // This method can be called when a control is already attached to the logical tree // in the following scenario: // - ListBox gets assigned Items containing ListBoxItem // - ListBox makes ListBoxItem a logical child // - ListBox template gets applied; making its Panel get attached to logical tree // - That AttachedToLogicalTree signal travels down to the ListBoxItem if (!_isAttachedToLogicalTree) { 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); } }
/// <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); } }
/// <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); }