private static LinearGradientBrush GetTitleBrush () { var result = new LinearGradientBrush (); result.StartPoint = new Point (0, 0); result.EndPoint = new Point (0, 1); result.GradientStops.Add (new GradientStop (new Color (0x97, 0xb8, 0xe2), 0)); result.GradientStops.Add (new GradientStop (new Color (0x4e, 0x76, 0xa8), 1)); return result; }
protected override void OnRender (DrawingContext dc) { if (Child == null) return; var x = BorderThickness / 2; var y = BorderThickness / 2; var width = Width - BorderThickness; var height = Height - BorderThickness; var figure = new PathFigure (); figure.StartPoint = new Point (x + CornerRadius.TopLeft, y); figure.IsClosed = true; figure.Segments.Add (new LineSegment () { Point = new Point(x + width - CornerRadius.TopRight, y)}); if (CornerRadius.TopRight > 0) { figure.Segments.Add (new ArcSegment () { Point = new Point(x + width, y + CornerRadius.TopRight), Size = new Size(CornerRadius.TopRight, CornerRadius.TopRight), SweepDirection = SweepDirection.Clockwise, IsLargeArc = false } ); } figure.Segments.Add (new LineSegment () { Point = new Point(x + width, y + height - CornerRadius.BottomRight) }); if (CornerRadius.BottomRight > 0) { figure.Segments.Add (new ArcSegment () { Point = new Point(x + width - CornerRadius.BottomRight, y + height), Size = new Size(CornerRadius.BottomRight, CornerRadius.BottomRight), SweepDirection = SweepDirection.Clockwise, IsLargeArc = false } ); } figure.Segments.Add (new LineSegment () { Point = new Point(x + CornerRadius.BottomLeft, y + height) }); if (CornerRadius.BottomLeft > 0) { figure.Segments.Add (new ArcSegment () { Point = new Point(x, y + height - CornerRadius.BottomLeft), Size = new Size(CornerRadius.BottomLeft, CornerRadius.BottomLeft), SweepDirection = SweepDirection.Clockwise, IsLargeArc = false } ); } figure.Segments.Add (new LineSegment () { Point = new Point(x, y + CornerRadius.TopLeft) }); if (CornerRadius.TopLeft > 0) { figure.Segments.Add (new ArcSegment () { Point = new Point(x + CornerRadius.TopLeft, y), Size = new Size(CornerRadius.TopLeft, CornerRadius.TopLeft), SweepDirection = SweepDirection.Clockwise, IsLargeArc = false } ); } var path = new PathGeometry (); path.Figures.Add (figure); //todo: resove it var brush = Background; if (brush is LinearGradientBrush) { var b = brush as LinearGradientBrush; var newBrush = new LinearGradientBrush () { StartPoint = new Point (b.StartPoint.X * width, b.StartPoint.Y * height), EndPoint = new Point (b.EndPoint.X * width, b.EndPoint.Y * height) }; newBrush.GradientStops.AddRange (b.GradientStops); brush = newBrush; } dc.DrawGeometry (brush, new Pen (BorderColor, BorderThickness), path); }