UserControlにカスタムUIElementsを使用したUIElementCollectionがあります。ただし、UIElementsは表示されません。どうしたの?
public partial class MyControl : UserControl
{
public static readonly DependencyProperty ChildrenProperty = DependencyProperty.Register("Children", typeof(UIElementCollection), typeof(MyControl), null);
public UIElementCollection Children
{
get { return (UIElementCollection)GetValue(ChildrenProperty); }
set { SetValue(ChildrenProperty, value); }
}
protected override Size MeasureOverride(Size availableSize)
{
Children.Clear();
UserControl child = new SecondUserControl();
child.Measure(availableSize);
Children.Add(child);
}
protected override Size ArrangeOverride(Size finalSize)
{
foreach (UIElement child in Children)
{
child.Arrange(new Rect(0,0, child.DesiredSize.Width, child.DesiredSize.Height));
}
return finalSize;
}
}