protected virtual void OnLineConnected(LineToDrawEventArgs e) { if (LineConnected != null) { LineConnected(this, e); } }
private void OnLineDraw(object sender, LineToDrawEventArgs args) { this.Dispatcher.Invoke(() => { void Line_MouseDown(object _sender, MouseButtonEventArgs e, float x1, float x2, float y1, float y2) { Console.WriteLine("X1: " + x1.ToString() + " X2: " + x2.ToString() + " Y1: " + y1.ToString() + " Y2: " + y2.ToString()); } if (args.P1 != null && args.P2 != null) { float[] limits = pr.getGridLimits(); float xMin = limits[0]; float xMax = limits[1]; float yMin = limits[2]; float yMax = limits[3]; float uiWidth = Convert.ToSingle(uiCanvas.Width); float uiHeight = Convert.ToSingle(uiCanvas.Height); float x1 = Utilities.normalizeValueBetweenRange(args.P1.getX(), xMin, xMax, 0, uiWidth); float x2 = Utilities.normalizeValueBetweenRange(args.P2.getX(), xMin, xMax, 0, uiWidth); float y1 = Utilities.normalizeValueBetweenRange(args.P1.getY(), yMin, yMax, 0, uiHeight); float y2 = Utilities.normalizeValueBetweenRange(args.P2.getY(), yMin, yMax, 0, uiHeight); Line line = new Line(); Brush brush = new SolidColorBrush(args.Color); line.Stroke = brush; line.X1 = x1; line.X2 = x2; line.Y1 = y1; line.Y2 = y2; line.MouseDown += (_sender, e) => Line_MouseDown(_sender, e, args.P1.getX(), args.P2.getX(), args.P1.getY(), args.P2.getY()); line.StrokeThickness = 2; uiCanvas.Children.Add(line); } if (args.Alt_P1 != null && args.Alt_p2 != null) { float[] limits = pr.getGridLimits(); float xMin = limits[0]; float xMax = limits[1]; float yMin = limits[2]; float yMax = limits[3]; float uiWidth = Convert.ToSingle(uiCanvas.Width); float uiHeight = Convert.ToSingle(uiCanvas.Height); float x1 = Utilities.normalizeValueBetweenRange(args.Alt_P1.getX(), xMin, xMax, 0, uiWidth); float x2 = Utilities.normalizeValueBetweenRange(args.Alt_p2.getX(), xMin, xMax, 0, uiWidth); float y1 = Utilities.normalizeValueBetweenRange(args.Alt_P1.getY(), yMin, yMax, 0, uiHeight); float y2 = Utilities.normalizeValueBetweenRange(args.Alt_p2.getY(), yMin, yMax, 0, uiHeight); Line line = new Line(); Brush brush = new SolidColorBrush(args.Color); line.Stroke = brush; line.X1 = x1; line.X2 = x2; line.Y1 = y1; line.Y2 = y2; line.MouseDown += (_sender, e) => Line_MouseDown(_sender, e, args.Alt_P1.getX(), args.Alt_p2.getX(), args.Alt_P1.getY(), args.Alt_p2.getY()); line.StrokeThickness = 2; uiCanvas.Children.Add(line); } }); }