0

Im working on drawing application. I made custom ruler control but i stucked in gridline support. My ruler looks like this: https://i.stack.imgur.com/dRUE3.jpg

RulerControl OnRender method:

protected override void OnRender(DrawingContext drawingContext)
{
   RenderOptions.SetEdgeMode(this, EdgeMode.Aliased);
   double psuedoStartValue = StartValue;
      #region Vertical Ruler
            psuedoStartValue = -(StartValue);
            for (int i = 0; i < this.ActualHeight / MajorInterval; i++)
            {
                var ft = new FormattedText((psuedoStartValue * MajorInterval).ToString(), System.Globalization.CultureInfo.CurrentUICulture, FlowDirection.LeftToRight, new Typeface("Tahoma"), 10, Brushes.Black);
                drawingContext.DrawText(ft, new Point(0, i * MajorInterval));
                drawingContext.DrawLine(new Pen(new SolidColorBrush(Colors.Red), 1), new Point(MarkLength, i * MajorInterval), new Point(0, i * MajorInterval));
                drawingContext.DrawLine(new Pen(new SolidColorBrush(Colors.Red), 1), new Point(MarkLength, i * MajorInterval), new Point(0, i * MajorInterval));
                drawingContext.DrawLine(new Pen(new SolidColorBrush(Colors.Green), 1),
                    new Point(MiddleMarkLength, i * MajorInterval + (MajorInterval / 2)),
                    new Point(0, i * MajorInterval + (MajorInterval / 2)));
                for (int j = 1; j < 10; j++)
                {
                    if (j==5)
                    {
                        continue;
                    }
                    drawingContext.DrawLine(new Pen(new SolidColorBrush(Colors.Blue), 1),
                    new Point(LittleMarkLength, i * MajorInterval + (((MajorInterval*j) / 10))),
                    new Point(0, i * MajorInterval + (((MajorInterval*j) / 10))));
                }
                psuedoStartValue--;
            }
        #endregion

        #region Mouse Tracking

        if (this.Orientation == enumOrientation.Horizontal)
        {
            drawingContext.DrawLine(mouseTrackPen,
                new Point(mousePosition.X, this.ActualHeight), new Point(mousePosition.X, 0));
        }
        #endregion
  }

When user moves mouse in window, ruler should show gridline. Im getting mouse position with Mouse.GetPosition(this) method. But i cant draw dynamic gridline in ruler. How i implement this issue?

Zafer Ayan
  • 791
  • 1
  • 7
  • 15
  • You want to draw it on the ruler, on the entire canvas, what happens if user zooms in/out? – Noctis Nov 11 '13 at 00:02
  • Im working on polygon connection animation in computional geometry course. I used rules as x-y axis of coordinate system. Therefore, i dont think zoom in/out events. – Zafer Ayan Nov 11 '13 at 00:42

0 Answers0