File size: 3,599 Bytes
8c763fb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | // 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
{
/// <content>
/// Partial class implementation for UIElementAdorner.
/// </content>
internal partial class UIElementAdorner : Adorner
{
private VisualCollection children;
/// <summary>
/// Constructs an instance of UIElementAdorner.
/// </summary>
/// <param name="adornedElement">The adorned element.</param>
public UIElementAdorner(UIElement adornedElement)
: base(adornedElement)
{
this.children = new VisualCollection(this);
}
/// <summary>
/// Overrides Visual.GetVisualChild, and returns a child at the specified index from a collection of child elements.
/// </summary>
/// <param name="index">The zero-based index of the requested child element in the collection..</param>
/// <returns>The requested child element. This should not return null; if the provided index is out of range, an exception is thrown.</returns>
protected override Visual GetVisualChild(int index)
{
return this.children[index];
}
/// <summary>
/// Gets the number of visual child elements within this element.
/// </summary>
protected override int VisualChildrenCount
{
get
{
return this.children.Count;
}
}
/// <summary>
/// Implements any custom measuring behavior for the popupAdorner.
/// </summary>
/// <param name="constraint">A size to constrain the popupAdorner to..</param>
/// <returns>A Size object representing the amount of layout space needed by the popupAdorner.</returns>
protected override Size MeasureOverride(Size constraint)
{
if (this.Child != null)
{
this.Child.Measure(constraint);
return this.Child.DesiredSize;
}
else
{
return base.MeasureOverride(constraint);
}
}
/// <summary>
/// When overridden in a derived class, positions child elements and determines a size for a FrameworkElement derived class.
/// </summary>
/// <param name="finalSize">The final area within the parent that this element should use to arrange itself and its children.</param>
/// <returns>The actual size used.</returns>
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<UIElement> 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);
}
}
}
}
|