Esempio n. 1
0
        /// <summary>Called to remeasure a <see cref="T:System.Windows.Controls.ToolBarTray" />. </summary>
        /// <param name="constraint">The measurement constraints; a <see cref="T:System.Windows.Controls.ToolBarTray" /> cannot return a size larger than the constraint.</param>
        /// <returns>The size of the control.</returns>
        // Token: 0x06005854 RID: 22612 RVA: 0x00187148 File Offset: 0x00185348
        protected override Size MeasureOverride(Size constraint)
        {
            this.GenerateBands();
            Size result        = default(Size);
            bool flag          = this.Orientation == Orientation.Horizontal;
            Size availableSize = new Size(double.PositiveInfinity, double.PositiveInfinity);

            for (int i = 0; i < this._bands.Count; i++)
            {
                double         num  = flag ? constraint.Width : constraint.Height;
                List <ToolBar> band = this._bands[i].Band;
                double         num2 = 0.0;
                double         num3 = 0.0;
                for (int j = 0; j < band.Count; j++)
                {
                    ToolBar toolBar = band[j];
                    num -= toolBar.MinLength;
                    if (DoubleUtil.LessThan(num, 0.0))
                    {
                        num = 0.0;
                        break;
                    }
                }
                for (int j = 0; j < band.Count; j++)
                {
                    ToolBar toolBar2 = band[j];
                    num += toolBar2.MinLength;
                    if (flag)
                    {
                        availableSize.Width = num;
                    }
                    else
                    {
                        availableSize.Height = num;
                    }
                    toolBar2.Measure(availableSize);
                    num2  = Math.Max(num2, flag ? toolBar2.DesiredSize.Height : toolBar2.DesiredSize.Width);
                    num3 += (flag ? toolBar2.DesiredSize.Width : toolBar2.DesiredSize.Height);
                    num  -= (flag ? toolBar2.DesiredSize.Width : toolBar2.DesiredSize.Height);
                    if (DoubleUtil.LessThan(num, 0.0))
                    {
                        num = 0.0;
                    }
                }
                this._bands[i].Thickness = num2;
                if (flag)
                {
                    result.Height += num2;
                    result.Width   = Math.Max(result.Width, num3);
                }
                else
                {
                    result.Width += num2;
                    result.Height = Math.Max(result.Height, num3);
                }
            }
            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// Updates DesiredSize of the ToolBarTray. Called by parent UIElement.
        /// This is the first pass of layout.
        /// MeasureOverride distributes all ToolBars in bands depend on Band and BandIndex properties.
        /// All ToolBars with the same Band are places in one band. After that they are sorted by BandIndex.
        /// </summary>
        /// <param name="constraint">Constraint size is an "upper limit" that ToolBarTray should not exceed.</param>
        /// <returns>ToolBarTray' desired size.</returns>
        protected override Size MeasureOverride(Size constraint)
        {
            GenerateBands();

            Size toolBarTrayDesiredSize = new Size();
            int  bandIndex;
            int  toolBarIndex;
            bool fHorizontal     = (Orientation == Orientation.Horizontal);
            Size childConstraint = new Size(Double.PositiveInfinity, Double.PositiveInfinity);

            for (bandIndex = 0; bandIndex < _bands.Count; bandIndex++)
            {
                // Calculate the available size before we measure the children.
                // remainingLength is the constraint minus sum of all minimum sizes
                double         remainingLength = fHorizontal ? constraint.Width : constraint.Height;
                List <ToolBar> band            = _bands[bandIndex].Band;
                double         bandThickness   = 0d;
                double         bandLength      = 0d;
                for (toolBarIndex = 0; toolBarIndex < band.Count; toolBarIndex++)
                {
                    ToolBar toolBar = band[toolBarIndex];
                    remainingLength -= toolBar.MinLength;
                    if (DoubleUtil.LessThan(remainingLength, 0))
                    {
                        remainingLength = 0;
                        break;
                    }
                }

                // Measure all children passing the remainingLength as a constraint
                for (toolBarIndex = 0; toolBarIndex < band.Count; toolBarIndex++)
                {
                    ToolBar toolBar = band[toolBarIndex];
                    remainingLength += toolBar.MinLength;
                    if (fHorizontal)
                    {
                        childConstraint.Width = remainingLength;
                    }
                    else
                    {
                        childConstraint.Height = remainingLength;
                    }
                    toolBar.Measure(childConstraint);
                    bandThickness    = Math.Max(bandThickness, fHorizontal ? toolBar.DesiredSize.Height : toolBar.DesiredSize.Width);
                    bandLength      += fHorizontal ? toolBar.DesiredSize.Width : toolBar.DesiredSize.Height;
                    remainingLength -= fHorizontal ? toolBar.DesiredSize.Width : toolBar.DesiredSize.Height;
                    if (DoubleUtil.LessThan(remainingLength, 0))
                    {
                        remainingLength = 0;
                    }
                }

                // Store band thickness in the BandInfo property
                _bands[bandIndex].Thickness = bandThickness;

                if (fHorizontal)
                {
                    toolBarTrayDesiredSize.Height += bandThickness;
                    toolBarTrayDesiredSize.Width   = Math.Max(toolBarTrayDesiredSize.Width, bandLength);
                }
                else
                {
                    toolBarTrayDesiredSize.Width += bandThickness;
                    toolBarTrayDesiredSize.Height = Math.Max(toolBarTrayDesiredSize.Height, bandLength);
                }
            }

            return(toolBarTrayDesiredSize);
        }