public override void Measure(Size availableSize) { Orientation orientation = Orientation; var baseSize = (orientation == Orientation.Horizontal) ? new Size(double.PositiveInfinity, availableSize.Height) : new Size(availableSize.Width, double.PositiveInfinity); var totalSize = new Size(); ChildRectDic.Clear(); foreach (var child in Children) { child.Measure(baseSize); var size = child.DesiredSize; switch (orientation) { case Orientation.Horizontal: ChildRectDic.Add(child, new Rect(new Point(totalSize.Width, 0), size)); totalSize.Height = Math.Max(totalSize.Height, size.Height); totalSize.Width += size.Width; break; case Orientation.Vertical: ChildRectDic.Add(child, new Rect(new Point(0, totalSize.Height), size)); totalSize.Height += size.Height; totalSize.Width = Math.Max(totalSize.Width, size.Width); break; } } DesiredSize = totalSize; }
public override void Measure(Size availableSize) { var columnCount = ColumnDefinitions.Count; if (columnCount == 0) { return; } _columnWidthArray = new double[columnCount]; _rowHeighArray = new double[(Children.Count + columnCount - 1) / ColumnDefinitions.Count]; // MEMO : 行と桁のサイズを確定します。 { int row = 0, column = 0; foreach (var child in Children) { if (child.MeasureDirty) { child.Measure(availableSize); } var size = child.DesiredSize; _columnWidthArray[column] = Math.Max(_columnWidthArray[column], size.Width); _rowHeighArray[row] = Math.Max(_rowHeighArray[row], size.Height); if (++column >= columnCount) { row++; column = 0; } } } // MEMO : 矩形をキャッシュします。 { int row = 0, column = 0; var location = new Point(); ChildRectDic.Clear(); foreach (var child in Children) { ChildRectDic.Add(child, new Rect(location, child.DesiredSize)); location.X += _columnWidthArray[column]; if (++column >= columnCount) { location.Y += _rowHeighArray[row]; location.X = 0; row++; column = 0; } } } DesiredSize = new Size(_columnWidthArray.Sum(), _rowHeighArray.Sum()); }
public override void Measure(Size availableSize) { var totalRect = new Rect(); ChildRectDic.Clear(); foreach (var child in Children) { child.Measure(availableSize); var size = child.DesiredSize; var location = GetChilldLocation(child); var rect = new Rect(location, size); ChildRectDic.Add(child, rect); totalRect.Union(rect); } DesiredSize = totalRect.Size; }