Beispiel #1
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            drawingContext.DrawRectangle(whiteBrush, null, new Rect(0, 0, this.ActualWidth, this.ActualHeight));

            if (this.Ramp == null)
            {
                return;
            }

            double width  = this.Ramp.Rails.Cast <RailRampItem>().Sum(r => r.Length);
            double height = this.Ramp.LayerHeigh;

            var transform = new TransformGroup();

            transform.Children.Add(new ScaleTransform(this.factor, this.factor));
            //transform.Children.Add(new TranslateTransform(0, height));
            drawingContext.PushTransform(transform);

            drawingContext.DrawLine(bluePen, new Point(0, 0), new Point(width, 0));
            drawingContext.DrawLine(redPen, new Point(0, height), new Point(width, height));

            try
            {
                //drawingContext.DrawRectangle(null, blackPen, new Rect(10, 10, width-20, height-20));
                Point from = new Point(0, height);
                Point to   = new Point(0, 0);
                foreach (var item in this.Ramp.Rails.Cast <RailRampItem>())
                {
                    //var p = new Point(item.Length, 0);
                    //p = p.Rotate(item.Gradient);
                    double dh = Gradient.CalcHeight(item.Gradient, item.Length);
                    to = from + new Vector(item.Length, -dh);

                    drawingContext.DrawLine(blackPen, from, to);

                    double perc = Gradient.AngleToPercent(item.Gradient);

                    Point pos = new Point(from.X + item.Length / 2, height);
                    drawingContext.DrawText(new FormattedText($"{perc:F2}%", CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Verdana"), 12 / this.factor, blackBrush, 1.25), pos);
                    drawingContext.DrawText(new FormattedText($"{item.Gradient:F2}°", CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Verdana"), 12 / this.factor, blackBrush, 1.25), pos + new Vector(0, 12 / this.factor));
                    drawingContext.DrawText(new FormattedText($"{dh:F2}mm", CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Verdana"), 12 / this.factor, blackBrush, 1.25), pos + new Vector(0, 24 / this.factor));
                    drawingContext.DrawText(new FormattedText($"{item.Length:F2}mm", CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Verdana"), 12 / this.factor, blackBrush, 1.25), pos + new Vector(0, 36 / this.factor));



                    from = to;

                    drawingContext.DrawEllipse(null, blackPen, from, 5, 5);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }


            drawingContext.Pop();
        }