我正在开发绘图应用程序。我制作了自定义标尺控件,但我坚持使用网格线支持。我的尺子看起来像这样:http: //i.stack.imgur.com/dRUE3.jpg
RulerControl OnRender 方法:
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
}
当用户在窗口中移动鼠标时,标尺应显示网格线。我使用 Mouse.GetPosition(this) 方法获取鼠标位置。但我不能在标尺中绘制动态网格线。我如何实现这个问题?