private void LayoutChild( NativeView child, LayoutParams layoutParams, Rectangle arrangeRect) { if (null == child) { throw new ArgumentNullException(nameof(child)); } if (null == layoutParams) { throw new ArgumentNullException(nameof(layoutParams)); } var childLayoutProperties = child.LayoutProperties(); // Handle gravity flags LayoutAxis axis = GetLayoutAxis(layoutParams.DockRegion); float childLeft = arrangeRect.Left + layoutParams.Margin.Left; float childLayoutWidth = childLayoutProperties.MeasuredSize.Width; var horizontalAlignment = layoutParams.HorizontalAlignment; if (horizontalAlignment == LayoutAlignment.Center) { childLeft = arrangeRect.Left + layoutParams.Margin.Left + ((arrangeRect.Width - (layoutParams.Margin.Left + childLayoutProperties.MeasuredSize.Width + layoutParams.Margin.Right)) / 2); } else if (horizontalAlignment == LayoutAlignment.End) { childLeft = arrangeRect.Right - (childLayoutProperties.MeasuredSize.Width + layoutParams.Margin.Right); } else if ((horizontalAlignment == LayoutAlignment.Fill) && (axis != LayoutAxis.Horizontal)) { // Use the entire available width (minus the margins) to layout the child childLayoutWidth = arrangeRect.Width - layoutParams.Margin.Left - layoutParams.Margin.Right; } float childTop = arrangeRect.Top + layoutParams.Margin.Top; float childLayoutHeight = childLayoutProperties.MeasuredSize.Height; var verticalAlignment = layoutParams.VerticalAlignment; if (verticalAlignment == LayoutAlignment.Center) { childTop = arrangeRect.Top + layoutParams.Margin.Top + ((arrangeRect.Height - (layoutParams.Margin.Top + childLayoutProperties.MeasuredSize.Height + layoutParams.Margin.Bottom)) / 2); } else if (verticalAlignment == LayoutAlignment.End) { childTop = arrangeRect.Bottom - (childLayoutProperties.MeasuredSize.Height + layoutParams.Margin.Bottom); } else if ((verticalAlignment == LayoutAlignment.Fill) && (axis != LayoutAxis.Vertical)) { // Use the entire available height (minus the margins) to layout the child childLayoutHeight = arrangeRect.Height - layoutParams.Margin.Top - layoutParams.Margin.Bottom; } // Layout the child with gravity taken into account child.Layout( childLeft, childTop, Math.Max(0, childLeft + childLayoutWidth), Math.Max(0, childTop + childLayoutHeight)); }