/// <summary>Measures the child elements of a <see cref="T:System.Windows.Controls.Border" /> before they are arranged during the <see cref="M:System.Windows.Controls.Border.ArrangeOverride(System.Windows.Size)" /> pass.</summary>
        /// <param name="constraint">An upper <see cref="T:System.Windows.Size" /> limit that cannot be exceeded.</param>
        /// <returns>The <see cref="T:System.Windows.Size" /> that represents the upper size limit of the element.</returns>
        // Token: 0x06004264 RID: 16996 RVA: 0x0012F824 File Offset: 0x0012DA24
        protected override Size MeasureOverride(Size constraint)
        {
            UIElement child           = this.Child;
            Size      result          = default(Size);
            Thickness borderThickness = this.BorderThickness;

            if (base.UseLayoutRounding && !FrameworkAppContextSwitches.DoNotApplyLayoutRoundingToMarginsAndBorderThickness)
            {
                DpiScale dpi = base.GetDpi();
                borderThickness = new Thickness(UIElement.RoundLayoutValue(borderThickness.Left, dpi.DpiScaleX), UIElement.RoundLayoutValue(borderThickness.Top, dpi.DpiScaleY), UIElement.RoundLayoutValue(borderThickness.Right, dpi.DpiScaleX), UIElement.RoundLayoutValue(borderThickness.Bottom, dpi.DpiScaleY));
            }
            Size size  = Border.HelperCollapseThickness(borderThickness);
            Size size2 = Border.HelperCollapseThickness(this.Padding);

            if (child != null)
            {
                Size size3         = new Size(size.Width + size2.Width, size.Height + size2.Height);
                Size availableSize = new Size(Math.Max(0.0, constraint.Width - size3.Width), Math.Max(0.0, constraint.Height - size3.Height));
                child.Measure(availableSize);
                Size desiredSize = child.DesiredSize;
                result.Width  = desiredSize.Width + size3.Width;
                result.Height = desiredSize.Height + size3.Height;
            }
            else
            {
                result = new Size(size.Width + size2.Width, size.Height + size2.Height);
            }
            return(result);
        }
Esempio n. 2
0
        // Token: 0x06004DDF RID: 19935 RVA: 0x0015F644 File Offset: 0x0015D844
        private void MoveSplitter(double horizontalChange, double verticalChange)
        {
            DpiScale dpi = base.GetDpi();
            double   num;

            if (this._resizeData.ResizeDirection == GridResizeDirection.Columns)
            {
                num = horizontalChange;
                if (base.UseLayoutRounding)
                {
                    num = UIElement.RoundLayoutValue(num, dpi.DpiScaleX);
                }
            }
            else
            {
                num = verticalChange;
                if (base.UseLayoutRounding)
                {
                    num = UIElement.RoundLayoutValue(num, dpi.DpiScaleY);
                }
            }
            DefinitionBase definition  = this._resizeData.Definition1;
            DefinitionBase definition2 = this._resizeData.Definition2;

            if (definition != null && definition2 != null)
            {
                double actualLength  = this.GetActualLength(definition);
                double actualLength2 = this.GetActualLength(definition2);
                if (this._resizeData.SplitBehavior == GridSplitter.SplitBehavior.Split && !LayoutDoubleUtil.AreClose(actualLength + actualLength2, this._resizeData.OriginalDefinition1ActualLength + this._resizeData.OriginalDefinition2ActualLength))
                {
                    this.CancelResize();
                    return;
                }
                double val;
                double val2;
                this.GetDeltaConstraints(out val, out val2);
                if (base.FlowDirection != this._resizeData.Grid.FlowDirection)
                {
                    num = -num;
                }
                num = Math.Min(Math.Max(num, val), val2);
                double num2 = actualLength + num;
                double definition2Pixels = actualLength + actualLength2 - num2;
                this.SetLengths(num2, definition2Pixels);
            }
        }
Esempio n. 3
0
        //-------------------------------------------------------------------
        //
        //  Protected Methods
        //
        //-------------------------------------------------------------------

        #region Protected Methods

        /// <summary>
        /// Updates DesiredSize of the Border.  Called by parent UIElement.  This is the first pass of layout.
        /// </summary>
        /// <remarks>
        /// Border determines its desired size it needs from the specified border the child: its sizing
        /// properties, margin, and requested size.
        /// </remarks>
        /// <param name="constraint">Constraint size is an "upper limit" that the return value should not exceed.</param>
        /// <returns>The Decorator's desired size.</returns>
        protected override Size MeasureOverride(Size constraint)
        {
            UIElement child   = Child;
            Size      mySize  = new Size();
            Thickness borders = this.BorderThickness;

            if (this.UseLayoutRounding && !FrameworkAppContextSwitches.DoNotApplyLayoutRoundingToMarginsAndBorderThickness)
            {
                double dpiScaleX = FrameworkElement.DpiScaleX;
                double dpiScaleY = FrameworkElement.DpiScaleY;
                borders = new Thickness(UIElement.RoundLayoutValue(borders.Left, dpiScaleX), UIElement.RoundLayoutValue(borders.Top, dpiScaleY),
                                        UIElement.RoundLayoutValue(borders.Right, dpiScaleX), UIElement.RoundLayoutValue(borders.Bottom, dpiScaleY));
            }
            // Compute the chrome size added by the various elements
            Size border  = HelperCollapseThickness(borders);
            Size padding = HelperCollapseThickness(this.Padding);

            //If we have a child
            if (child != null)
            {
                // Combine into total decorating size
                Size combined = new Size(border.Width + padding.Width, border.Height + padding.Height);

                // Remove size of border only from child's reference size.
                Size childConstraint = new Size(Math.Max(0.0, constraint.Width - combined.Width),
                                                Math.Max(0.0, constraint.Height - combined.Height));


                child.Measure(childConstraint);
                Size childSize = child.DesiredSize;

                // Now use the returned size to drive our size, by adding back the margins, etc.
                mySize.Width  = childSize.Width + combined.Width;
                mySize.Height = childSize.Height + combined.Height;
            }
            else
            {
                // Combine into total decorating size
                mySize = new Size(border.Width + padding.Width, border.Height + padding.Height);
            }

            return(mySize);
        }
Esempio n. 4
0
        // Move the splitter by the given Delta's in the horizontal and vertical directions
        private void MoveSplitter(double horizontalChange, double verticalChange)
        {
            Debug.Assert(_resizeData != null, "_resizeData should not be null when calling MoveSplitter");

            double   delta;
            DpiScale dpi = GetDpi();

            // Calculate the offset to adjust the splitter.  If layout rounding is enabled, we
            // need to round to an integer physical pixel value to avoid round-ups of children that
            // expand the bounds of the Grid.  In practice this only happens in high dpi because
            // horizontal/vertical offsets here are never fractional (they correspond to mouse movement
            // across logical pixels).  Rounding error only creeps in when converting to a physical
            // display with something other than the logical 96 dpi.
            if (_resizeData.ResizeDirection == GridResizeDirection.Columns)
            {
                delta = horizontalChange;
                if (this.UseLayoutRounding)
                {
                    delta = UIElement.RoundLayoutValue(delta, dpi.DpiScaleX);
                }
            }
            else
            {
                delta = verticalChange;
                if (this.UseLayoutRounding)
                {
                    delta = UIElement.RoundLayoutValue(delta, dpi.DpiScaleY);
                }
            }

            DefinitionBase definition1 = _resizeData.Definition1;
            DefinitionBase definition2 = _resizeData.Definition2;

            if (definition1 != null && definition2 != null)
            {
                double actualLength1 = GetActualLength(definition1);
                double actualLength2 = GetActualLength(definition2);

                // When splitting, Check to see if the total pixels spanned by the definitions
                // is the same asbefore starting resize. If not cancel the drag
                if (_resizeData.SplitBehavior == SplitBehavior.Split &&
                    !LayoutDoubleUtil.AreClose(actualLength1 + actualLength2, _resizeData.OriginalDefinition1ActualLength + _resizeData.OriginalDefinition2ActualLength))
                {
                    CancelResize();
                    return;
                }

                double min, max;
                GetDeltaConstraints(out min, out max);

                // Flip when the splitter's flow direction isn't the same as the grid's
                if (FlowDirection != _resizeData.Grid.FlowDirection)
                {
                    delta = -delta;
                }

                // Constrain Delta to Min/MaxWidth of columns
                delta = Math.Min(Math.Max(delta, min), max);

                // With floating point operations there may be loss of precision to some degree. Eg. Adding a very
                // small value to a very large one might result in the small value being ignored. In the following
                // steps there are two floating point operations viz. actualLength1+delta and actualLength2-delta.
                // It is possible that the addition resulted in loss of precision and the delta value was ignored, whereas
                // the subtraction actual absorbed the delta value. This now means that
                // (definition1LengthNew + definition2LengthNewis) 2 factors of precision away from
                // (actualLength1 + actualLength2). This can cause a problem in the subsequent drag iteration where
                // this will be interpreted as the cancellation of the resize operation. To avoid this imprecision we use
                // make definition2LengthNew be a function of definition1LengthNew so that the precision or the loss
                // thereof can be counterbalanced. See DevDiv bug#140228 for a manifestation of this problem.

                double definition1LengthNew = actualLength1 + delta;
                //double definition2LengthNew = actualLength2 - delta;
                double definition2LengthNew = actualLength1 + actualLength2 - definition1LengthNew;

                SetLengths(definition1LengthNew, definition2LengthNew);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// In addition to the child, Border renders a background + border.  The background is drawn inside the border.
        /// </summary>
        protected override void OnRender(DrawingContext dc)
        {
            bool     useLayoutRounding = this.UseLayoutRounding;
            DpiScale dpi = GetDpi();

            if (_useComplexRenderCodePath)
            {
                Brush          brush;
                StreamGeometry borderGeometry = BorderGeometryCache;
                if (borderGeometry != null &&
                    (brush = BorderBrush) != null)
                {
                    dc.DrawGeometry(brush, null, borderGeometry);
                }

                StreamGeometry backgroundGeometry = BackgroundGeometryCache;
                if (backgroundGeometry != null &&
                    (brush = Background) != null)
                {
                    dc.DrawGeometry(brush, null, backgroundGeometry);
                }
            }
            else
            {
                Thickness border = BorderThickness;
                Brush     borderBrush;

                CornerRadius cornerRadius      = CornerRadius;
                double       outerCornerRadius = cornerRadius.TopLeft; // Already validated that all corners have the same radius
                bool         roundedCorners    = !DoubleUtil.IsZero(outerCornerRadius);

                // If we have a brush with which to draw the border, do so.
                // NB: We double draw corners right now.  Corner handling is tricky (bevelling, &c...) and
                //     we need a firm spec before doing "the right thing."  (greglett, ffortes)
                if (!border.IsZero &&
                    (borderBrush = BorderBrush) != null)
                {
                    // Initialize the first pen.  Note that each pen is created via new()
                    // and frozen if possible.  Doing this avoids the pen
                    // being copied when used in the DrawLine methods.
                    Pen pen = LeftPenCache;
                    if (pen == null)
                    {
                        pen       = new Pen();
                        pen.Brush = borderBrush;

                        if (useLayoutRounding)
                        {
                            pen.Thickness = UIElement.RoundLayoutValue(border.Left, dpi.DpiScaleX);
                        }
                        else
                        {
                            pen.Thickness = border.Left;
                        }
                        if (borderBrush.IsFrozen)
                        {
                            pen.Freeze();
                        }

                        LeftPenCache = pen;
                    }

                    double halfThickness;
                    if (border.IsUniform)
                    {
                        halfThickness = pen.Thickness * 0.5;


                        // Create rect w/ border thickness, and round if applying layout rounding.
                        Rect rect = new Rect(new Point(halfThickness, halfThickness),
                                             new Point(RenderSize.Width - halfThickness, RenderSize.Height - halfThickness));

                        if (roundedCorners)
                        {
                            dc.DrawRoundedRectangle(
                                null,
                                pen,
                                rect,
                                outerCornerRadius,
                                outerCornerRadius);
                        }
                        else
                        {
                            dc.DrawRectangle(
                                null,
                                pen,
                                rect);
                        }
                    }
                    else
                    {
                        // Nonuniform border; stroke each edge.
                        if (DoubleUtil.GreaterThan(border.Left, 0))
                        {
                            halfThickness = pen.Thickness * 0.5;
                            dc.DrawLine(
                                pen,
                                new Point(halfThickness, 0),
                                new Point(halfThickness, RenderSize.Height));
                        }

                        if (DoubleUtil.GreaterThan(border.Right, 0))
                        {
                            pen = RightPenCache;
                            if (pen == null)
                            {
                                pen       = new Pen();
                                pen.Brush = borderBrush;

                                if (useLayoutRounding)
                                {
                                    pen.Thickness = UIElement.RoundLayoutValue(border.Right, dpi.DpiScaleX);
                                }
                                else
                                {
                                    pen.Thickness = border.Right;
                                }

                                if (borderBrush.IsFrozen)
                                {
                                    pen.Freeze();
                                }

                                RightPenCache = pen;
                            }

                            halfThickness = pen.Thickness * 0.5;
                            dc.DrawLine(
                                pen,
                                new Point(RenderSize.Width - halfThickness, 0),
                                new Point(RenderSize.Width - halfThickness, RenderSize.Height));
                        }

                        if (DoubleUtil.GreaterThan(border.Top, 0))
                        {
                            pen = TopPenCache;
                            if (pen == null)
                            {
                                pen       = new Pen();
                                pen.Brush = borderBrush;
                                if (useLayoutRounding)
                                {
                                    pen.Thickness = UIElement.RoundLayoutValue(border.Top, dpi.DpiScaleY);
                                }
                                else
                                {
                                    pen.Thickness = border.Top;
                                }

                                if (borderBrush.IsFrozen)
                                {
                                    pen.Freeze();
                                }

                                TopPenCache = pen;
                            }

                            halfThickness = pen.Thickness * 0.5;
                            dc.DrawLine(
                                pen,
                                new Point(0, halfThickness),
                                new Point(RenderSize.Width, halfThickness));
                        }

                        if (DoubleUtil.GreaterThan(border.Bottom, 0))
                        {
                            pen = BottomPenCache;
                            if (pen == null)
                            {
                                pen       = new Pen();
                                pen.Brush = borderBrush;
                                if (useLayoutRounding)
                                {
                                    pen.Thickness = UIElement.RoundLayoutValue(border.Bottom, dpi.DpiScaleY);
                                }
                                else
                                {
                                    pen.Thickness = border.Bottom;
                                }
                                if (borderBrush.IsFrozen)
                                {
                                    pen.Freeze();
                                }

                                BottomPenCache = pen;
                            }

                            halfThickness = pen.Thickness * 0.5;
                            dc.DrawLine(
                                pen,
                                new Point(0, RenderSize.Height - halfThickness),
                                new Point(RenderSize.Width, RenderSize.Height - halfThickness));
                        }
                    }
                }

                // Draw background in rectangle inside border.
                Brush background = Background;
                if (background != null)
                {
                    // Intialize background
                    Point ptTL, ptBR;

                    if (useLayoutRounding)
                    {
                        ptTL = new Point(UIElement.RoundLayoutValue(border.Left, dpi.DpiScaleX),
                                         UIElement.RoundLayoutValue(border.Top, dpi.DpiScaleY));

                        if (FrameworkAppContextSwitches.DoNotApplyLayoutRoundingToMarginsAndBorderThickness)
                        {
                            ptBR = new Point(UIElement.RoundLayoutValue(RenderSize.Width - border.Right, dpi.DpiScaleX),
                                             UIElement.RoundLayoutValue(RenderSize.Height - border.Bottom, dpi.DpiScaleY));
                        }
                        else
                        {
                            ptBR = new Point(RenderSize.Width - UIElement.RoundLayoutValue(border.Right, dpi.DpiScaleX),
                                             RenderSize.Height - UIElement.RoundLayoutValue(border.Bottom, dpi.DpiScaleY));
                        }
                    }
                    else
                    {
                        ptTL = new Point(border.Left, border.Top);
                        ptBR = new Point(RenderSize.Width - border.Right, RenderSize.Height - border.Bottom);
                    }

                    // Do not draw background if the borders are so large that they overlap.
                    if (ptBR.X > ptTL.X && ptBR.Y > ptTL.Y)
                    {
                        if (roundedCorners)
                        {
                            Radii  innerRadii        = new Radii(cornerRadius, border, false); // Determine the inner edge radius
                            double innerCornerRadius = innerRadii.TopLeft;                     // Already validated that all corners have the same radius
                            dc.DrawRoundedRectangle(background, null, new Rect(ptTL, ptBR), innerCornerRadius, innerCornerRadius);
                        }
                        else
                        {
                            dc.DrawRectangle(background, null, new Rect(ptTL, ptBR));
                        }
                    }
                }
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Border computes the position of its single child and applies its child's alignments to the child.
        ///
        /// </summary>
        /// <param name="finalSize">The size reserved for this element by the parent</param>
        /// <returns>The actual ink area of the element, typically the same as finalSize</returns>
        protected override Size ArrangeOverride(Size finalSize)
        {
            Thickness borders = BorderThickness;

            if (this.UseLayoutRounding && !FrameworkAppContextSwitches.DoNotApplyLayoutRoundingToMarginsAndBorderThickness)
            {
                DpiScale dpi = GetDpi();
                borders = new Thickness(UIElement.RoundLayoutValue(borders.Left, dpi.DpiScaleX), UIElement.RoundLayoutValue(borders.Top, dpi.DpiScaleY),
                                        UIElement.RoundLayoutValue(borders.Right, dpi.DpiScaleX), UIElement.RoundLayoutValue(borders.Bottom, dpi.DpiScaleY));
            }
            Rect boundRect = new Rect(finalSize);
            Rect innerRect = HelperDeflateRect(boundRect, borders);

            //  arrange child
            UIElement child = Child;

            if (child != null)
            {
                Rect childRect = HelperDeflateRect(innerRect, Padding);
                child.Arrange(childRect);
            }

            CornerRadius radii          = CornerRadius;
            Brush        borderBrush    = BorderBrush;
            bool         uniformCorners = AreUniformCorners(radii);

            //  decide which code path to execute. complex (geometry path based) rendering
            //  is used if one of the following is true:

            //  1. there are non-uniform rounded corners
            _useComplexRenderCodePath = !uniformCorners;

            if (!_useComplexRenderCodePath &&
                borderBrush != null)
            {
                SolidColorBrush originIndependentBrush = borderBrush as SolidColorBrush;

                bool uniformBorders = borders.IsUniform;

                _useComplexRenderCodePath =
                    //  2. the border brush is origin dependent (the only origin independent brush is a solid color brush)
                    (originIndependentBrush == null)
                    //  3. the border brush is semi-transtarent solid color brush AND border thickness is not uniform
                    //     (for uniform semi-transparent border Border.OnRender draws rectangle outline - so it works fine)
                    || ((originIndependentBrush.Color.A < 0xff) && !uniformBorders)
                    //  4. there are rounded corners AND the border thickness is not uniform
                    || (!DoubleUtil.IsZero(radii.TopLeft) && !uniformBorders);
            }

            if (_useComplexRenderCodePath)
            {
                Radii innerRadii = new Radii(radii, borders, false);

                StreamGeometry backgroundGeometry = null;

                //  calculate border / background rendering geometry
                if (!DoubleUtil.IsZero(innerRect.Width) && !DoubleUtil.IsZero(innerRect.Height))
                {
                    backgroundGeometry = new StreamGeometry();

                    using (StreamGeometryContext ctx = backgroundGeometry.Open())
                    {
                        GenerateGeometry(ctx, innerRect, innerRadii);
                    }

                    backgroundGeometry.Freeze();
                    BackgroundGeometryCache = backgroundGeometry;
                }
                else
                {
                    BackgroundGeometryCache = null;
                }

                if (!DoubleUtil.IsZero(boundRect.Width) && !DoubleUtil.IsZero(boundRect.Height))
                {
                    Radii          outerRadii     = new Radii(radii, borders, true);
                    StreamGeometry borderGeometry = new StreamGeometry();

                    using (StreamGeometryContext ctx = borderGeometry.Open())
                    {
                        GenerateGeometry(ctx, boundRect, outerRadii);

                        if (backgroundGeometry != null)
                        {
                            GenerateGeometry(ctx, innerRect, innerRadii);
                        }
                    }

                    borderGeometry.Freeze();
                    BorderGeometryCache = borderGeometry;
                }
                else
                {
                    BorderGeometryCache = null;
                }
            }
            else
            {
                BackgroundGeometryCache = null;
                BorderGeometryCache     = null;
            }

            return(finalSize);
        }
        /// <summary>Draws the contents of a <see cref="T:System.Windows.Media.DrawingContext" /> object during the render pass of a <see cref="T:System.Windows.Controls.Border" />. </summary>
        /// <param name="dc">The <see cref="T:System.Windows.Media.DrawingContext" /> that defines the object to be drawn.</param>
        // Token: 0x06004266 RID: 16998 RVA: 0x0012FBE0 File Offset: 0x0012DDE0
        protected override void OnRender(DrawingContext dc)
        {
            bool     useLayoutRounding = base.UseLayoutRounding;
            DpiScale dpi = base.GetDpi();

            if (this._useComplexRenderCodePath)
            {
                StreamGeometry borderGeometryCache = this.BorderGeometryCache;
                Brush          brush;
                if (borderGeometryCache != null && (brush = this.BorderBrush) != null)
                {
                    dc.DrawGeometry(brush, null, borderGeometryCache);
                }
                StreamGeometry backgroundGeometryCache = this.BackgroundGeometryCache;
                if (backgroundGeometryCache != null && (brush = this.Background) != null)
                {
                    dc.DrawGeometry(brush, null, backgroundGeometryCache);
                    return;
                }
            }
            else
            {
                Thickness    borderThickness = this.BorderThickness;
                CornerRadius cornerRadius    = this.CornerRadius;
                double       topLeft         = cornerRadius.TopLeft;
                bool         flag            = !DoubleUtil.IsZero(topLeft);
                Brush        borderBrush;
                if (!borderThickness.IsZero && (borderBrush = this.BorderBrush) != null)
                {
                    Pen pen = this.LeftPenCache;
                    if (pen == null)
                    {
                        pen       = new Pen();
                        pen.Brush = borderBrush;
                        if (useLayoutRounding)
                        {
                            pen.Thickness = UIElement.RoundLayoutValue(borderThickness.Left, dpi.DpiScaleX);
                        }
                        else
                        {
                            pen.Thickness = borderThickness.Left;
                        }
                        if (borderBrush.IsFrozen)
                        {
                            pen.Freeze();
                        }
                        this.LeftPenCache = pen;
                    }
                    if (borderThickness.IsUniform)
                    {
                        double num       = pen.Thickness * 0.5;
                        Rect   rectangle = new Rect(new Point(num, num), new Point(base.RenderSize.Width - num, base.RenderSize.Height - num));
                        if (flag)
                        {
                            dc.DrawRoundedRectangle(null, pen, rectangle, topLeft, topLeft);
                        }
                        else
                        {
                            dc.DrawRectangle(null, pen, rectangle);
                        }
                    }
                    else
                    {
                        if (DoubleUtil.GreaterThan(borderThickness.Left, 0.0))
                        {
                            double num = pen.Thickness * 0.5;
                            dc.DrawLine(pen, new Point(num, 0.0), new Point(num, base.RenderSize.Height));
                        }
                        if (DoubleUtil.GreaterThan(borderThickness.Right, 0.0))
                        {
                            pen = this.RightPenCache;
                            if (pen == null)
                            {
                                pen       = new Pen();
                                pen.Brush = borderBrush;
                                if (useLayoutRounding)
                                {
                                    pen.Thickness = UIElement.RoundLayoutValue(borderThickness.Right, dpi.DpiScaleX);
                                }
                                else
                                {
                                    pen.Thickness = borderThickness.Right;
                                }
                                if (borderBrush.IsFrozen)
                                {
                                    pen.Freeze();
                                }
                                this.RightPenCache = pen;
                            }
                            double num = pen.Thickness * 0.5;
                            dc.DrawLine(pen, new Point(base.RenderSize.Width - num, 0.0), new Point(base.RenderSize.Width - num, base.RenderSize.Height));
                        }
                        if (DoubleUtil.GreaterThan(borderThickness.Top, 0.0))
                        {
                            pen = this.TopPenCache;
                            if (pen == null)
                            {
                                pen       = new Pen();
                                pen.Brush = borderBrush;
                                if (useLayoutRounding)
                                {
                                    pen.Thickness = UIElement.RoundLayoutValue(borderThickness.Top, dpi.DpiScaleY);
                                }
                                else
                                {
                                    pen.Thickness = borderThickness.Top;
                                }
                                if (borderBrush.IsFrozen)
                                {
                                    pen.Freeze();
                                }
                                this.TopPenCache = pen;
                            }
                            double num = pen.Thickness * 0.5;
                            dc.DrawLine(pen, new Point(0.0, num), new Point(base.RenderSize.Width, num));
                        }
                        if (DoubleUtil.GreaterThan(borderThickness.Bottom, 0.0))
                        {
                            pen = this.BottomPenCache;
                            if (pen == null)
                            {
                                pen       = new Pen();
                                pen.Brush = borderBrush;
                                if (useLayoutRounding)
                                {
                                    pen.Thickness = UIElement.RoundLayoutValue(borderThickness.Bottom, dpi.DpiScaleY);
                                }
                                else
                                {
                                    pen.Thickness = borderThickness.Bottom;
                                }
                                if (borderBrush.IsFrozen)
                                {
                                    pen.Freeze();
                                }
                                this.BottomPenCache = pen;
                            }
                            double num = pen.Thickness * 0.5;
                            dc.DrawLine(pen, new Point(0.0, base.RenderSize.Height - num), new Point(base.RenderSize.Width, base.RenderSize.Height - num));
                        }
                    }
                }
                Brush background = this.Background;
                if (background != null)
                {
                    Point point;
                    Point point2;
                    if (useLayoutRounding)
                    {
                        point = new Point(UIElement.RoundLayoutValue(borderThickness.Left, dpi.DpiScaleX), UIElement.RoundLayoutValue(borderThickness.Top, dpi.DpiScaleY));
                        if (FrameworkAppContextSwitches.DoNotApplyLayoutRoundingToMarginsAndBorderThickness)
                        {
                            point2 = new Point(UIElement.RoundLayoutValue(base.RenderSize.Width - borderThickness.Right, dpi.DpiScaleX), UIElement.RoundLayoutValue(base.RenderSize.Height - borderThickness.Bottom, dpi.DpiScaleY));
                        }
                        else
                        {
                            point2 = new Point(base.RenderSize.Width - UIElement.RoundLayoutValue(borderThickness.Right, dpi.DpiScaleX), base.RenderSize.Height - UIElement.RoundLayoutValue(borderThickness.Bottom, dpi.DpiScaleY));
                        }
                    }
                    else
                    {
                        point  = new Point(borderThickness.Left, borderThickness.Top);
                        point2 = new Point(base.RenderSize.Width - borderThickness.Right, base.RenderSize.Height - borderThickness.Bottom);
                    }
                    if (point2.X > point.X && point2.Y > point.Y)
                    {
                        if (flag)
                        {
                            Border.Radii radii    = new Border.Radii(cornerRadius, borderThickness, false);
                            double       topLeft2 = radii.TopLeft;
                            dc.DrawRoundedRectangle(background, null, new Rect(point, point2), topLeft2, topLeft2);
                            return;
                        }
                        dc.DrawRectangle(background, null, new Rect(point, point2));
                    }
                }
            }
        }
        /// <summary>Arranges the contents of a <see cref="T:System.Windows.Controls.Border" /> element.</summary>
        /// <param name="finalSize">The <see cref="T:System.Windows.Size" /> this element uses to arrange its child element.</param>
        /// <returns>The <see cref="T:System.Windows.Size" /> that represents the arranged size of this <see cref="T:System.Windows.Controls.Border" /> element and its child element.</returns>
        // Token: 0x06004265 RID: 16997 RVA: 0x0012F998 File Offset: 0x0012DB98
        protected override Size ArrangeOverride(Size finalSize)
        {
            Thickness borderThickness = this.BorderThickness;

            if (base.UseLayoutRounding && !FrameworkAppContextSwitches.DoNotApplyLayoutRoundingToMarginsAndBorderThickness)
            {
                DpiScale dpi = base.GetDpi();
                borderThickness = new Thickness(UIElement.RoundLayoutValue(borderThickness.Left, dpi.DpiScaleX), UIElement.RoundLayoutValue(borderThickness.Top, dpi.DpiScaleY), UIElement.RoundLayoutValue(borderThickness.Right, dpi.DpiScaleX), UIElement.RoundLayoutValue(borderThickness.Bottom, dpi.DpiScaleY));
            }
            Rect      rect  = new Rect(finalSize);
            Rect      rect2 = Border.HelperDeflateRect(rect, borderThickness);
            UIElement child = this.Child;

            if (child != null)
            {
                Rect finalRect = Border.HelperDeflateRect(rect2, this.Padding);
                child.Arrange(finalRect);
            }
            CornerRadius cornerRadius = this.CornerRadius;
            Brush        borderBrush  = this.BorderBrush;
            bool         flag         = Border.AreUniformCorners(cornerRadius);

            this._useComplexRenderCodePath = !flag;
            if (!this._useComplexRenderCodePath && borderBrush != null)
            {
                SolidColorBrush solidColorBrush = borderBrush as SolidColorBrush;
                bool            isUniform       = borderThickness.IsUniform;
                this._useComplexRenderCodePath = (solidColorBrush == null || (solidColorBrush.Color.A < byte.MaxValue && !isUniform) || (!DoubleUtil.IsZero(cornerRadius.TopLeft) && !isUniform));
            }
            if (this._useComplexRenderCodePath)
            {
                Border.Radii   radii          = new Border.Radii(cornerRadius, borderThickness, false);
                StreamGeometry streamGeometry = null;
                if (!DoubleUtil.IsZero(rect2.Width) && !DoubleUtil.IsZero(rect2.Height))
                {
                    streamGeometry = new StreamGeometry();
                    using (StreamGeometryContext streamGeometryContext = streamGeometry.Open())
                    {
                        Border.GenerateGeometry(streamGeometryContext, rect2, radii);
                    }
                    streamGeometry.Freeze();
                    this.BackgroundGeometryCache = streamGeometry;
                }
                else
                {
                    this.BackgroundGeometryCache = null;
                }
                if (!DoubleUtil.IsZero(rect.Width) && !DoubleUtil.IsZero(rect.Height))
                {
                    Border.Radii   radii2          = new Border.Radii(cornerRadius, borderThickness, true);
                    StreamGeometry streamGeometry2 = new StreamGeometry();
                    using (StreamGeometryContext streamGeometryContext2 = streamGeometry2.Open())
                    {
                        Border.GenerateGeometry(streamGeometryContext2, rect, radii2);
                        if (streamGeometry != null)
                        {
                            Border.GenerateGeometry(streamGeometryContext2, rect2, radii);
                        }
                    }
                    streamGeometry2.Freeze();
                    this.BorderGeometryCache = streamGeometry2;
                }
                else
                {
                    this.BorderGeometryCache = null;
                }
            }
            else
            {
                this.BackgroundGeometryCache = null;
                this.BorderGeometryCache     = null;
            }
            return(finalSize);
        }