/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Button2_Checked(object sender, RoutedEventArgs e) { using (DrawingContext dc = _grid.RenderOpen()) { // vertical. dc.DrawLine(_gridPen, new Point(0, 40), new Point(301, 40)); dc.DrawLine(_gridPen, new Point(0, 80), new Point(301, 80)); dc.DrawLine(_gridPen, new Point(0, 120), new Point(301, 120)); dc.DrawLine(_gridPen, new Point(0, 160), new Point(301, 160)); // horizontal. dc.DrawLine(_gridPen, new Point(60, 0), new Point(60, 201)); dc.DrawLine(_gridPen, new Point(120, 0), new Point(120, 201)); dc.DrawLine(_gridPen, new Point(180, 0), new Point(180, 201)); dc.DrawLine(_gridPen, new Point(240, 0), new Point(240, 201)); DrawingSpace.AddVisual(_grid); } }
/// <summary> /// /// </summary> private void _DrawShape() { List <Point> points = _CalculatePoints(); DrawingVisual visual = new DrawingVisual(); using (DrawingContext dc = visual.RenderOpen()) { if (points.Count > 0) { Point start = points[0]; foreach (Point p in points) { dc.DrawLine(_pen, start, p); start = p; } } DrawingSpace.DeleteVisual(_visual); _visual = visual; DrawingSpace.AddVisual(_visual); } }