using System; using System.Diagnostics; using Avalonia.Rendering; namespace Avalonia { /// /// Holds the event arguments for the and /// events. /// public class VisualTreeAttachmentEventArgs : EventArgs { /// /// Initializes a new instance of the class. /// /// The parent that the visual's tree is being attached to or detached from. /// Presentation source this visual is being attached to. public VisualTreeAttachmentEventArgs(Visual? attachmentPoint, IPresentationSource presentationSource) { RootVisual = presentationSource.RootVisual ?? throw new InvalidOperationException("PresentationSource must have a non-null RootVisual."); AttachmentPoint = attachmentPoint; PresentationSource = presentationSource ?? throw new ArgumentNullException(nameof(presentationSource)); } /// /// Gets the parent that the visual's tree is being attached to or detached from, null means that /// the entire tree is being attached to a PresentationSource /// public Visual? AttachmentPoint { get; } [Obsolete("Use " + nameof(AttachmentPoint))] public Visual? Parent => AttachmentPoint; /// /// Gets the root of the visual tree that the visual is being attached to or detached from. /// public IPresentationSource PresentationSource { get; } [Obsolete("This was previously always returning TopLevel. This is no longer guaranteed. Use TopLevel.GetTopLevel(this) if you need a TopLevel or args.RootVisual if you are interested in the root of the visual tree.")] public Visual Root => RootVisual; /// /// The root visual of the tree this visual is being attached to or detached from. /// This is guaranteed to be non-null and will be the same as . /// public Visual RootVisual { get; set; } } }