Пример #1
0
 private void MeasureChild(UIElement child, double availableMainLength, double availableCrossLength)
 {
     child.Measure(Orientation == Orientation.Horizontal ?
         new Size(availableMainLength, availableCrossLength) :
         new Size(availableCrossLength, availableMainLength));
 }
        private void InsertDisplayedElement(int slot, UIElement element, bool wasNewlyAdded, bool updateSlotInformation)
        {
            // We can only support creating new rows that are adjacent to the currently visible rows
            // since they need to be added to the visual tree for us to Measure them.
            Debug.Assert(this.DisplayData.FirstScrollingSlot == -1 || slot >= GetPreviousVisibleSlot(this.DisplayData.FirstScrollingSlot) && slot <= GetNextVisibleSlot(this.DisplayData.LastScrollingSlot));
            Debug.Assert(element != null);
            
            if (this._rowsPresenter != null)
            {
                DataGridRowGroupHeader groupHeader = null;
                DataGridRow row = element as DataGridRow;
                if (row != null)
                {
                    LoadRowVisualsForDisplay(row);

                    if (IsRowRecyclable(row))
                    {
                        if (!row.IsRecycled)
                        {
                            Debug.Assert(!this._rowsPresenter.Children.Contains(element));
                            _rowsPresenter.Children.Add(row);
                        }
                    }
                    else
                    {
                        element.Clip = null;
                        Debug.Assert(row.Index == RowIndexFromSlot(slot));
                    }
                }
                else
                {
                    groupHeader = element as DataGridRowGroupHeader;
                    Debug.Assert(groupHeader != null);  // Nothig other and Rows and RowGroups now
                    if (groupHeader != null)
                    {
                        groupHeader.TotalIndent = (groupHeader.Level == 0) ? 0 : this.RowGroupSublevelIndents[groupHeader.Level - 1];
                        if (!groupHeader.IsRecycled)
                        {
                            _rowsPresenter.Children.Add(element);
                        }
                        groupHeader.LoadVisualsForDisplay();

                        Style lastStyle = _rowGroupHeaderStyles.Count > 0 ? _rowGroupHeaderStyles[_rowGroupHeaderStyles.Count - 1] : null;
                        EnsureElementStyle(groupHeader, groupHeader.Style, groupHeader.Level < _rowGroupHeaderStyles.Count ? _rowGroupHeaderStyles[groupHeader.Level] : lastStyle);
                    }
                }

                // Measure the element and update AvailableRowRoom
                element.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
                this.AvailableSlotElementRoom -= element.DesiredSize.Height;

                if (groupHeader != null)
                {
                    _rowGroupHeightsByLevel[groupHeader.Level] = groupHeader.DesiredSize.Height;
                }

                if (row != null && this.RowHeightEstimate == DataGrid.DATAGRID_defaultRowHeight && double.IsNaN(row.Height))
                {
                    this.RowHeightEstimate = element.DesiredSize.Height;
                }
            }

            if (wasNewlyAdded)
            {
                this.DisplayData.CorrectSlotsAfterInsertion(slot, element, false /*isCollapsed*/);
            }
            else
            {
                this.DisplayData.LoadScrollingSlot(slot, element, updateSlotInformation);
            }
        }
Пример #3
0
        // Token: 0x06005698 RID: 22168 RVA: 0x0017F0C4 File Offset: 0x0017D2C4
        internal static Size StackMeasureHelper(IStackMeasure measureElement, IStackMeasureScrollData scrollData, Size constraint)
        {
            Size size = default(Size);
            UIElementCollection internalChildren = measureElement.InternalChildren;
            Size   availableSize = constraint;
            bool   flag          = measureElement.Orientation == Orientation.Horizontal;
            int    num           = -1;
            int    i;
            double num2;

            if (flag)
            {
                availableSize.Width = double.PositiveInfinity;
                if (measureElement.IsScrolling && measureElement.CanVerticallyScroll)
                {
                    availableSize.Height = double.PositiveInfinity;
                }
                i    = (measureElement.IsScrolling ? StackPanel.CoerceOffsetToInteger(scrollData.Offset.X, internalChildren.Count) : 0);
                num2 = constraint.Width;
            }
            else
            {
                availableSize.Height = double.PositiveInfinity;
                if (measureElement.IsScrolling && measureElement.CanHorizontallyScroll)
                {
                    availableSize.Width = double.PositiveInfinity;
                }
                i    = (measureElement.IsScrolling ? StackPanel.CoerceOffsetToInteger(scrollData.Offset.Y, internalChildren.Count) : 0);
                num2 = constraint.Height;
            }
            int j     = 0;
            int count = internalChildren.Count;

            while (j < count)
            {
                UIElement uielement = internalChildren[j];
                if (uielement != null)
                {
                    uielement.Measure(availableSize);
                    Size   desiredSize = uielement.DesiredSize;
                    double num3;
                    if (flag)
                    {
                        size.Width += desiredSize.Width;
                        size.Height = Math.Max(size.Height, desiredSize.Height);
                        num3        = desiredSize.Width;
                    }
                    else
                    {
                        size.Width   = Math.Max(size.Width, desiredSize.Width);
                        size.Height += desiredSize.Height;
                        num3         = desiredSize.Height;
                    }
                    if (measureElement.IsScrolling && num == -1 && j >= i)
                    {
                        num2 -= num3;
                        if (DoubleUtil.LessThanOrClose(num2, 0.0))
                        {
                            num = j;
                        }
                    }
                }
                j++;
            }
            if (measureElement.IsScrolling)
            {
                Size   viewport = constraint;
                Size   extent   = size;
                Vector offset   = scrollData.Offset;
                if (num == -1)
                {
                    num = internalChildren.Count - 1;
                }
                while (i > 0)
                {
                    double num4 = num2;
                    if (flag)
                    {
                        num4 -= internalChildren[i - 1].DesiredSize.Width;
                    }
                    else
                    {
                        num4 -= internalChildren[i - 1].DesiredSize.Height;
                    }
                    if (DoubleUtil.LessThan(num4, 0.0))
                    {
                        break;
                    }
                    i--;
                    num2 = num4;
                }
                int count2 = internalChildren.Count;
                int num5   = num - i;
                if (num5 == 0 || DoubleUtil.GreaterThanOrClose(num2, 0.0))
                {
                    num5++;
                }
                if (flag)
                {
                    scrollData.SetPhysicalViewport(viewport.Width);
                    viewport.Width = (double)num5;
                    extent.Width   = (double)count2;
                    offset.X       = (double)i;
                    offset.Y       = Math.Max(0.0, Math.Min(offset.Y, extent.Height - viewport.Height));
                }
                else
                {
                    scrollData.SetPhysicalViewport(viewport.Height);
                    viewport.Height = (double)num5;
                    extent.Height   = (double)count2;
                    offset.Y        = (double)i;
                    offset.X        = Math.Max(0.0, Math.Min(offset.X, extent.Width - viewport.Width));
                }
                size.Width  = Math.Min(size.Width, constraint.Width);
                size.Height = Math.Min(size.Height, constraint.Height);
                StackPanel.VerifyScrollingData(measureElement, scrollData, viewport, extent, offset);
            }
            return(size);
        }
Пример #4
0
 private void MeasureChild(UIElement child, double availableMainLength, double availableCrossLength)
 {
     child.Measure(Orientation == Orientation.Horizontal ?
                   new Size(availableMainLength, availableCrossLength) :
                   new Size(availableCrossLength, availableMainLength));
 }
        //-------------------------------------------------------------------
        //
        // Protected Methods
        //
        //-------------------------------------------------------------------

        #region Protected Methods

        /// <summary>
        /// Override of <seealso cref="FrameworkElement.MeasureOverride" />.
        /// </summary>
        /// <param name="constraint">Constraint size is an "upper limit" that the return value should not exceed.</param>
        /// <returns>The GridViewRowPresenter's desired size.</returns>
        protected override Size MeasureOverride(Size constraint)
        {
            GridViewColumnCollection columns = Columns;

            if (columns == null)
            {
                return(new Size());
            }

            UIElementCollection children   = InternalChildren;
            double maxHeight               = 0.0; // Max height of children.
            double accumulatedWidth        = 0.0; // Total width consumed by children.
            double constraintHeight        = constraint.Height;
            bool   desiredWidthListEnsured = false;

            foreach (GridViewColumn column in columns)
            {
                UIElement child = children[column.ActualIndex];
                if (child == null)
                {
                    continue;
                }

                double childConstraintWidth = Math.Max(0.0, constraint.Width - accumulatedWidth);

                if (column.State == ColumnMeasureState.Init ||
                    column.State == ColumnMeasureState.Headered)
                {
                    if (!desiredWidthListEnsured)
                    {
                        EnsureDesiredWidthList();
                        LayoutUpdated          += new EventHandler(OnLayoutUpdated);
                        desiredWidthListEnsured = true;
                    }

                    // Measure child.
                    child.Measure(new Size(childConstraintWidth, constraintHeight));

                    // As long as this is the first round of measure that has data participate
                    // the width should be ensured
                    // only element on current page paticipates in calculating the shared width
                    if (IsOnCurrentPage)
                    {
                        column.EnsureWidth(child.DesiredSize.Width);
                    }

                    DesiredWidthList[column.ActualIndex] = column.DesiredWidth;

                    accumulatedWidth += column.DesiredWidth;
                }
                else if (column.State == ColumnMeasureState.Data)
                {
                    childConstraintWidth = Math.Min(childConstraintWidth, column.DesiredWidth);

                    child.Measure(new Size(childConstraintWidth, constraintHeight));

                    accumulatedWidth += column.DesiredWidth;
                }
                else // ColumnMeasureState.SpecificWidth
                {
                    childConstraintWidth = Math.Min(childConstraintWidth, column.Width);

                    child.Measure(new Size(childConstraintWidth, constraintHeight));

                    accumulatedWidth += column.Width;
                }

                maxHeight = Math.Max(maxHeight, child.DesiredSize.Height);
            }

            // Reset this flag so that we will re-caculate it on every measure.
            _isOnCurrentPageValid = false;

            // reserve space for dummy header next to the last column
            accumulatedWidth += c_PaddingHeaderMinWidth;

            return(new Size(accumulatedWidth, maxHeight));
        }