public override Size MeasureChildren(string layoutId,
MetaPanelBase metaPanel,
MetaElementStateDict stateDict,
ICollection elements,
Size availableSize)
{
// Only apply if we match the incoming layout identifier
if (string.IsNullOrEmpty(Id) || Id.Equals(layoutId))
{
// Measure each element in turn
_validCount = 0;
Size usedSize = new Size();
Size maxSize = new Size();
foreach (UIElement element in elements)
{
// Allow element to have all the remainder size available
Size elementSize = new Size(Math.Max(0.0, (double)(availableSize.Width - usedSize.Width)),
Math.Max(0.0, (double)(availableSize.Height - usedSize.Height)));
element.Measure(elementSize);
// We ignore items being removed
if (stateDict[element].Status != MetaElementStatus.Removing)
{
// Discover the used size and the maximum required size for opposite direction
Size desiredSize = element.DesiredSize;
switch (GetDock(element))
{
case Dock.Left:
case Dock.Right:
maxSize.Height = Math.Max(maxSize.Height, usedSize.Height + desiredSize.Height);
usedSize.Width += desiredSize.Width;
break;
case Dock.Top:
case Dock.Bottom:
maxSize.Width = Math.Max(maxSize.Width, usedSize.Width + desiredSize.Width);
usedSize.Height += desiredSize.Height;
break;
}
_validCount++;
}
}
return new Size(Math.Max(maxSize.Width, usedSize.Width),
Math.Max(maxSize.Height, usedSize.Height));
}
else
return Size.Empty;
}