Пример #1
0
        /// <summary>
        /// Calculates the width of the child desired.
        /// </summary>
        /// <param name="child">The child.</param>
        /// <param name="parentColumn">The parent column.</param>
        /// <param name="finalSize">The final size.</param>
        /// <returns>Tuple{System.DoubleSizeSystem.Boolean}.</returns>
        private Tuple<double, Size, bool> CalculateChildDesiredWidth(ContentPresenter child, IColumn parentColumn, Size finalSize)
        {
            var childDesiredWidth = child.DesiredSize.Width;
            var finalSizeResult = finalSize;
            var desiredWidthCorrected = false;

            var lastChild = Children.Last();

            if (child.Equals(lastChild) && IsOutermost(child))
            {
                var permissibleWidth = 0.0;
                if (parentColumn == null)
                {
                    var topLevelColumn = child.Content as IColumn;
                    if (topLevelColumn != null)
                    {
                        var owner = topLevelColumn.Owner;
                        if (owner != null && owner.IsTopLevel)
                            permissibleWidth = owner.CalculateSpreadsheetWidth();
                    }
                }

                var totalDesiredWidth = Children.Sum(x => x.DesiredSize.Width);
                if (totalDesiredWidth < permissibleWidth)
                {
                    if (child.DesiredSize.Width.Equals(child.RenderSize.Width))
                    {
                        var delta = permissibleWidth - totalDesiredWidth;

                        childDesiredWidth = child.DesiredSize.Width + delta;
                        finalSize.Width += delta;
                    }
                    else
                    {
                        childDesiredWidth = child.RenderSize.Width;
                        finalSize.Width += (child.RenderSize.Width - child.DesiredSize.Width);
                    }

                    var column = child.Content as IColumn;
                    if (column != null)
                        column.Width = childDesiredWidth;

                    desiredWidthCorrected = true;
                }
            }

            return Tuple.Create(childDesiredWidth, finalSizeResult, desiredWidthCorrected);
        }