// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Documents; using System.Windows.Media; namespace Microsoft.Management.UI.Internal { /// /// Partial class implementation for UIElementAdorner. /// internal partial class UIElementAdorner : Adorner { private VisualCollection children; /// /// Constructs an instance of UIElementAdorner. /// /// The adorned element. public UIElementAdorner(UIElement adornedElement) : base(adornedElement) { this.children = new VisualCollection(this); } /// /// Overrides Visual.GetVisualChild, and returns a child at the specified index from a collection of child elements. /// /// The zero-based index of the requested child element in the collection.. /// The requested child element. This should not return null; if the provided index is out of range, an exception is thrown. protected override Visual GetVisualChild(int index) { return this.children[index]; } /// /// Gets the number of visual child elements within this element. /// protected override int VisualChildrenCount { get { return this.children.Count; } } /// /// Implements any custom measuring behavior for the popupAdorner. /// /// A size to constrain the popupAdorner to.. /// A Size object representing the amount of layout space needed by the popupAdorner. protected override Size MeasureOverride(Size constraint) { if (this.Child != null) { this.Child.Measure(constraint); return this.Child.DesiredSize; } else { return base.MeasureOverride(constraint); } } /// /// When overridden in a derived class, positions child elements and determines a size for a FrameworkElement derived class. /// /// The final area within the parent that this element should use to arrange itself and its children. /// The actual size used. protected override Size ArrangeOverride(Size finalSize) { if (this.Child != null) { Point location = new Point(0, 0); Rect rect = new Rect(location, finalSize); this.Child.Arrange(rect); return this.Child.RenderSize; } else { return base.ArrangeOverride(finalSize); } } partial void OnChildChangedImplementation(PropertyChangedEventArgs e) { if (e.OldValue != null) { this.children.Remove(e.OldValue); this.RemoveLogicalChild(e.OldValue); } if (this.Child != null) { this.children.Add(this.Child); this.AddLogicalChild(this.Child); } } } }