Files
HandyControl/HandyControl/Interactivity/AdornerContainer.cs
T
2019-03-12 00:47:25 +08:00

39 lines
945 B
C#

using System.Windows;
using System.Windows.Documents;
using System.Windows.Media;
namespace HandyControl.Interactivity
{
public class AdornerContainer : Adorner
{
private UIElement _child;
public AdornerContainer(UIElement adornedElement) : base(adornedElement)
{
}
public UIElement Child
{
get => _child;
set
{
AddVisualChild(value);
_child = value;
}
}
protected override int VisualChildrenCount => _child != null ? 1 : 0;
protected override Size ArrangeOverride(Size finalSize)
{
_child?.Arrange(new Rect(finalSize));
return finalSize;
}
protected override Visual GetVisualChild(int index)
{
if (index == 0 && _child != null) return _child;
return base.GetVisualChild(index);
}
}
}