/// <summary> /// Calls the <see cref="OnAttachedToVisualTree(VisualTreeAttachmentEventArgs)"/> method /// for this control and all of its visual descendants. /// </summary> /// <param name="e">The event args.</param> protected virtual void OnAttachedToVisualTreeCore(VisualTreeAttachmentEventArgs e) { Logger.TryGet(LogEventLevel.Verbose)?.Log(LogArea.Visual, this, "Attached to visual tree"); _visualRoot = e.Root; if (RenderTransform != null) { RenderTransform.Changed += RenderTransformChanged; } OnAttachedToVisualTree(e); AttachedToVisualTree?.Invoke(this, e); InvalidateVisual(); var visualChildren = VisualChildren; if (visualChildren != null) { var visualChildrenCount = visualChildren.Count; for (var i = 0; i < visualChildrenCount; i++) { if (visualChildren[i] is Visual child) { child.OnAttachedToVisualTreeCore(e); } } } }
/// <summary> /// Called when the control is added to a visual 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 OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e) { if (RenderTransform != null) { RenderTransform.Changed += RenderTransformChanged; } AttachedToVisualTree?.Invoke(this, e); }
/// <summary> /// Calls the <see cref="OnAttachedToVisualTree(VisualTreeAttachmentEventArgs)"/> method /// for this control and all of its visual descendants. /// </summary> /// <param name="e">The event args.</param> protected virtual void OnAttachedToVisualTreeCore(VisualTreeAttachmentEventArgs e) { Logger.Verbose(LogArea.Visual, this, "Attached to visual tree"); _visualRoot = e.Root; if (RenderTransform != null) { RenderTransform.Changed += RenderTransformChanged; } OnAttachedToVisualTree(e); AttachedToVisualTree?.Invoke(this, e); InvalidateVisual(); if (VisualChildren != null) { foreach (Visual child in VisualChildren.OfType <Visual>()) { child.OnAttachedToVisualTreeCore(e); } } }
/// <summary> /// Called when the control is added to a visual tree. /// </summary> /// <param name="e">The event args.</param> protected virtual void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e) { AttachedToVisualTree?.Invoke(this, e); }