private void DrawGrid(DrawingContext drawingContext) { double bottom = this.ActualHeight; Rect r = new Rect(0, 0, this.ActualWidth, bottom); ulong firstVisibleTick; ulong lastVisibleTick; ulong tickInterval; this.TimeAxis.GetTickInfo(out firstVisibleTick, out lastVisibleTick, out tickInterval); if (tickInterval == 0) { return; } double yFirstTic = 0; double yTicInterval = 1; double yMax = 100; if (this.SideBar != null) { this.SideBar.GetTickInfo(out yFirstTic, out yTicInterval, out yMax); } // Draw all tween grid lines before major grid lines if (xShowTween) { for (ulong x = firstVisibleTick + tickInterval / 2; x <= lastVisibleTick; x += tickInterval) { double tx = Math.Floor(TimeAxis.TimeToScreen(x)) + 0.5; drawingContext.DrawLine(gridPen, new Point(tx, r.Top), new Point(tx, r.Bottom)); } } if (yShowTween) { for (double y = yFirstTic + yTicInterval / 2; y < yMax; y += yTicInterval) { double ty = Math.Floor((bottom - 1) - SideBar.YToPixels(y)) + 0.5; drawingContext.DrawLine(gridPen, new Point(0, ty), new Point(this.ActualWidth, ty)); } } // Draw major grid lines for (ulong x = firstVisibleTick; x <= lastVisibleTick; x += tickInterval) { double tx = Math.Floor(TimeAxis.TimeToScreen(x)) + 0.5; drawingContext.DrawLine(gridPen, new Point(tx, r.Top), new Point(tx, r.Bottom)); } if (this.SideBar != null) { for (double y = yFirstTic; y < yMax; y += yTicInterval) { double ty = Math.Floor((bottom - 1) - SideBar.YToPixels(y)) + 0.5; drawingContext.DrawLine(gridPen, new Point(0, ty), new Point(this.ActualWidth, ty)); } } }