示例#1
0
        protected override SizeF CalculateInnerDesiredSize(SizeF totalSize)
        {
            if (ColumnDefinitions.Count == 0)
            {
                ColumnDefinitions.Add(new ColumnDefinition());
            }
            if (RowDefinitions.Count == 0)
            {
                RowDefinitions.Add(new RowDefinition());
            }

            // Reset values before we start measure the children.
            ColumnDefinitions.ResetAllCellLengths();
            RowDefinitions.ResetAllCellLengths();

            // Set the Width/Hight of the Columns/Rows according to the sizes of the children.
            foreach (FrameworkElement child in GetVisibleChildren())
            {
                int col = GetColumn(child);
                int row = GetRow(child);
                if (col >= ColumnDefinitions.Count)
                {
                    col = ColumnDefinitions.Count - 1;
                }
                if (col < 0)
                {
                    col = 0;
                }
                if (row >= RowDefinitions.Count)
                {
                    row = RowDefinitions.Count - 1;
                }
                if (row < 0)
                {
                    row = 0;
                }

                SizeF childSize = new SizeF(totalSize.Width, totalSize.Height);
                // FIXME Albert: Would be better to use the size which is really available for the child here,
                // but this is not so easy to calculate (depends on col/row definition(s), colspan/rowspan)
                child.Measure(ref childSize);
                ColumnDefinitions.SetDesiredLength(col, GetColumnSpan(child), childSize.Width);
                RowDefinitions.SetDesiredLength(row, GetRowSpan(child), childSize.Height);
            }
            return(new SizeF((float)ColumnDefinitions.TotalDesiredLength, (float)RowDefinitions.TotalDesiredLength));
        }