public override void Layout(ViewLayoutContext context)
{
Debug.Assert(context != null);
// Validate incoming reference
if (context == null) throw new ArgumentNullException("context");
// We take on all the available display area
Rectangle original = context.DisplayRectangle;
ClientRectangle = original;
// Layout each child
foreach (ViewBase child in this)
{
// Only layout visible children
if (child.Visible)
{
// Ask child for it's own preferred size
Size childPreferred = child.GetPreferredSize(context);
// Size child to our relevant dimension
if (_orientation == Orientation.Vertical)
context.DisplayRectangle = new Rectangle(ClientRectangle.X,
ClientRectangle.Y,
childPreferred.Width,
ClientRectangle.Height);
else
context.DisplayRectangle = new Rectangle(ClientRectangle.X,
ClientRectangle.Y,
childPreferred.Width,
ClientRectangle.Height);
// Finally ask the child to layout
child.Layout(context);
}
}
// Put back the original display value now we have finished
context.DisplayRectangle = original;
}