Example #1
0
        protected override void OnRender(DrawingContext dc)
        {
            Rect      bounds          = new Rect(0.0, 0.0, this.ActualWidth, this.ActualHeight);
            Thickness borderThickness = this.BorderThickness;
            double    num1            = borderThickness.Left + borderThickness.Right;
            double    num2            = borderThickness.Top + borderThickness.Bottom;
            bool      flag            = borderThickness.Left == 1.0 && borderThickness.Right == 1.0 && borderThickness.Top == 1.0 && borderThickness.Bottom == 1.0;
            double    num3            = num1 != 0.0 || num2 != 0.0 ? 1.0 : 0.0;
            double    num4            = 2.0 * num3;

            if (bounds.Width > num1 && bounds.Height > num2)
            {
                Rect  rectangle  = new Rect(bounds.Left + borderThickness.Left, bounds.Top + borderThickness.Top, bounds.Width - num1, bounds.Height - num2);
                Brush background = this.Background;
                if (background != null)
                {
                    dc.DrawRectangle(background, (Pen)null, rectangle);
                }
                if (bounds.Width > num1 + num4 && bounds.Height > num2 + num4)
                {
                    rectangle = new Rect(bounds.Left + borderThickness.Left + num3, bounds.Top + borderThickness.Top + num3, bounds.Width - num1 - num4, bounds.Height - num2 - num4);
                    Brush backgroundOverlay = this.BackgroundOverlay;
                    if (backgroundOverlay != null)
                    {
                        dc.DrawRoundedRectangle(backgroundOverlay, (Pen)null, rectangle, 1.0, 1.0);
                    }
                }
            }
            if (num3 <= 0.0 || bounds.Width < num1 || bounds.Height < num2)
            {
                return;
            }
            if (flag)
            {
                Rect rectangle        = new Rect(bounds.Left + 0.5, bounds.Top + 0.5, bounds.Width - 1.0, bounds.Height - 1.0);
                Pen  borderPen        = ListBoxChrome.GetBorderPen(this.BorderBrush);
                Pen  borderOverlayPen = this.BorderOverlayPen;
                if (borderPen != null)
                {
                    dc.DrawRoundedRectangle((Brush)null, borderPen, rectangle, 1.0, 1.0);
                }
                if (borderOverlayPen == null)
                {
                    return;
                }
                dc.DrawRoundedRectangle((Brush)null, borderOverlayPen, rectangle, 1.0, 1.0);
            }
            else
            {
                Geometry borderGeometry = ListBoxChrome.GetBorderGeometry(borderThickness, bounds);
                if (this.BorderBrush == null)
                {
                    return;
                }
                dc.DrawGeometry(this.BorderBrush, (Pen)null, borderGeometry);
            }
        }