示例#1
0
        /// <summary>
        /// 测量所有已经生成的单元格。
        /// </summary>
        /// <param name="columns"></param>
        /// <param name="availableSize"></param>
        /// <returns></returns>
        private Size MeasureChild(TreeGridColumnCollection columns, Size availableSize)
        {
            double maxWidth         = availableSize.Width;
            double maxHeight        = availableSize.Height;
            double rowDesiredHeight = 0.0;                 //行最终需要的高度
            double rowDesiredWidth  = 0.0;                 //行最终需要的宽度
            bool   firstTime        = true;                //是否在 Init 状态下还没有初始化过 DesiredWidthList。
            var    cells            = this.InternalChildren;

            for (int i = this._from, j = 0; i <= this._to; i++, j++)
            {
                var column = columns[i];

                //当前行还可用的宽度
                double rowAvaiableWidth = Math.Max(0, maxWidth - rowDesiredWidth);

                //第一列额外元素需要的宽度
                double headersDesiredWidth = 0;

                #region 测量第一列额外元素需要的宽度

                if (i == 0)
                {
                    //测量 RowHeader
                    if (this.ShowRowHeader)
                    {
                        headersDesiredWidth += this.RowHeaderWidth;
                        rowAvaiableWidth    -= this.RowHeaderWidth;
                        //this._rowHeaderContainer.Measure(new Size(columnWidth, maxHeight));
                        //x += this._rowHeaderContainer.DesiredSize.Width;
                        //columnWidth -= this._rowHeaderContainer.DesiredSize.Width;
                    }

                    //留下 FirstColumnIndent
                    var firstColumnIndent = Math.Min(this.FirstColumnIndent, rowAvaiableWidth);
                    headersDesiredWidth += firstColumnIndent;
                    rowAvaiableWidth    -= firstColumnIndent;

                    //测量 Expander
                    if (this.ShowExpander)
                    {
                        var expander = this.Expander;
                        expander.Measure(new Size(rowAvaiableWidth, maxHeight));
                        headersDesiredWidth += expander.DesiredSize.Width;
                        rowAvaiableWidth    -= expander.DesiredSize.Width;
                    }
                }

                #endregion

                var cell = cells[j];

                //测量单元格
                var state = column.State;
                if (state == ColumnMeasureState.Init || state == ColumnMeasureState.Headered)
                {
                    if (firstTime)
                    {
                        TreeGridHelper.EnsureDesiredWidthList(ref this._desiredWidthList, this._treeGrid.Columns);
                        this.LayoutUpdated += this.OnMeasureLayoutUpdated;
                        firstTime           = false;
                    }

                    cell.Measure(new Size(rowAvaiableWidth, maxHeight));

                    //只有在虚拟化后的当前页面时,才影响动态宽度。
                    if (this._cellsPresenter.IsOnCurrentPage)
                    {
                        //当前列需要的宽度应该是列的宽度加额外元素的宽度。
                        column.EnsureDataWidth(cell.DesiredSize.Width + headersDesiredWidth);
                    }
                    this._desiredWidthList[column.StableIndex] = column.DesiredDataWidth;

                    rowDesiredWidth += column.DesiredDataWidth;
                }
                else
                {
                    var actualWidth = column.CalculateActualWidth();

                    rowAvaiableWidth = Math.Min(rowAvaiableWidth, actualWidth - headersDesiredWidth);

                    cell.Measure(new Size(rowAvaiableWidth, maxHeight));

                    rowDesiredWidth += actualWidth;
                }

                rowDesiredHeight = Math.Max(rowDesiredHeight, cell.DesiredSize.Height);
            }

            rowDesiredWidth += TreeGridHeaderRowPresenter.c_EndPadding;

            this._cellsPresenter.IsOnCurrentPageValid = false;

            return(new Size(rowDesiredWidth, rowDesiredHeight));
        }
示例#2
0
 /// <summary>
 /// 保证 _desiredWidthList 与 columns 长度一致。
 /// </summary>
 internal void EnsureDesiredWidthList()
 {
     TreeGridHelper.EnsureDesiredWidthList(ref this._desiredWidthList, this.Columns);
 }