/// <summary> /// Perform a layout of the elements. /// </summary> /// <param name="context">Layout context.</param> public override void Layout(ViewLayoutContext context) { Debug.Assert(context != null); SyncData(context); SyncMonths(); // We take on all the available display area ClientRectangle = context.DisplayRectangle; // Is there a today header to layout? if (_drawHeader.Visible) { // Measure the required size of the header Size headerSize = _drawHeader.GetPreferredSize(context); // Position the header a the bottom of the area context.DisplayRectangle = new Rectangle(ClientLocation.X + GAP, ClientRectangle.Bottom - GAP - headerSize.Height, ClientSize.Width - GAP * 2, headerSize.Height); _drawHeader.Layout(context); } // Are there any month views to layout? if (Count > 1) { // Only need to measure the first child as all children must be the same size Size monthSize = this[1].GetPreferredSize(context); // Position each child within the required grid Size dimensions = _calendar.CalendarDimensions; for (int y = 0, index = 1; y < dimensions.Height; y++) { for (int x = 0; x < dimensions.Width; x++) { context.DisplayRectangle = new Rectangle(ClientLocation.X + (x * monthSize.Width) + (GAP * (x + 1)), ClientLocation.Y + (y * monthSize.Height) + (GAP * (y + 1)), monthSize.Width, monthSize.Height); this[index++].Layout(context); } } } // Put back the original display value now we have finished context.DisplayRectangle = ClientRectangle; }