public void Draw(DrawingContext context, DrawingArgs args) { context.PushClip(new RectangleGeometry(args.RenderBounds)); if (m_IsDirty || args.RequiresFullRedraw) { m_LonePoints.Clear(); System.Windows.Media.StreamGeometry geo = new StreamGeometry(); using (var c = geo.Open()) { Point? figureStart = null; int pointCount = 0; //point in the figure if (Values.Count() == 1 && Values.First().HasValue) { m_LonePoints.Add(Values.First().Value); } else { foreach (var p in Values) { if (p.HasValue) { if (!figureStart.HasValue) { figureStart = p.Value; c.BeginFigure(figureStart.Value, false, false); pointCount = 1; } else { c.LineTo(p.Value, true, true); pointCount++; } } else { //detect lone points and draw a cross if (pointCount == 1) { m_LonePoints.Add(figureStart.Value); } figureStart = null; } } } } m_Geo = geo; m_IsDirty = false; } m_Geo.Transform = args.Transform; context.DrawGeometry(null, Pen, m_Geo); var radius = Pen.Thickness; foreach (var p in m_LonePoints) { context.DrawEllipse(m_Pen.Brush, null, args.Transform.Transform(p), radius, radius); } }
public void Draw(System.Windows.Media.DrawingContext context, DrawingArgs args) { double lineWidth = 1; context.PushClip(new RectangleGeometry(args.RenderBounds)); var transformdPos = args.Transform.Transform(new Point(0, Position)).X; Point start = new Point(transformdPos, args.RenderBounds.Top); Point end = new Point(transformdPos, args.RenderBounds.Bottom); var offset = lineWidth / 2; context.PushGuidelineSet(new GuidelineSet( new[] { start.X + offset, end.X + offset }, new[] { start.Y + offset, end.Y + offset })); context.DrawLine(new Pen(new SolidColorBrush(Color), lineWidth), start, end); context.Pop(); }