/// <summary> /// Draws the line. /// </summary> /// <param name="point">The first point.</param> /// <param name="point2">The second point.</param> /// <param name="shape">The shape to be used.</param> protected void DrawLine(Point point, Point point2, Shape shape) { Size desiredSize; Point ensurePoint; Rect heightAndWidthRect; Point positionedPoint = new Point(0, 0); Point centerPoint = new Point(0, 0); double height = 0, width = 0; Path path = null; Line line = null; if (IsWithCap) { path = shape as Path; } else { line = shape as Line; } point.Y = (double.IsNaN(point.Y)) ? 0 : point.Y; point.X = (double.IsNaN(point.X)) ? 0 : point.X; point2.Y = (double.IsNaN(point2.Y)) ? 0 : point2.Y; point2.X = (double.IsNaN(point2.X)) ? 0 : point2.X; heightAndWidthRect = new Rect(point, point2); ensurePoint = this.EnsurePoint(point, point2); desiredSize = new Size(heightAndWidthRect.Width, heightAndWidthRect.Height); positionedPoint = GetElementPosition(new Size(heightAndWidthRect.Width, heightAndWidthRect.Height), ensurePoint); if (IsWithCap) { arrowLine.X1 = point.X; arrowLine.Y1 = point.Y; arrowLine.X2 = point2.X; arrowLine.Y2 = point2.Y; path.Data = arrowLine.GetGeometry() as PathGeometry; } else { line.X1 = point.X; line.Y1 = point.Y; line.X2 = point2.X; line.Y2 = point2.Y; } if (CanResize && farThumb != null && nearThumb != null) { Canvas.SetLeft(farThumb, point.X); Canvas.SetTop(farThumb, point.Y); Canvas.SetLeft(nearThumb, point2.X); Canvas.SetTop(nearThumb, point2.Y); } AnnotationElement.Width = heightAndWidthRect.Width; AnnotationElement.Height = heightAndWidthRect.Height; centerPoint = new Point( positionedPoint.X + (heightAndWidthRect.Width / 2), positionedPoint.Y + (heightAndWidthRect.Height / 2)); minimumSize = GrabExtent * 2; height = heightAndWidthRect.Height < minimumSize ? minimumSize : heightAndWidthRect.Height; width = heightAndWidthRect.Width < minimumSize ? minimumSize : heightAndWidthRect.Width; RotatedRect = new Rect(centerPoint.X - (width / 2), centerPoint.Y - (height / 2), width, height); LinePoints = new Point[2] { point, point2 }; if (!(this is HorizontalLineAnnotation || this is VerticalLineAnnotation)) { UpdateHitArea(); } if (TextElement.Content != null) { SetTextElementPosition(point, point2, desiredSize, positionedPoint, TextElement); } // This is to avoid line visibility collapse while dragging. if (LineCanvas != null && IsDragging) { LineCanvas.UpdateLayout(); } }