2,854 questions
You can use DrawingVisual and DrawingContext to draw the grid , something like:
DrawingVisual gridLinesVisual = new DrawingVisual();
DrawingContext dct = gridLinesVisual.RenderOpen();
Then use Pen and DrawingContext.DrawLine to draw the lines like below:
Pen lightPen = new Pen(_color1, 0.5), darkPen = new Pen(_color2, 1);
int yOffset = yoffSet,
xOffset = xoffSet,
rows = (int)(SystemParameters.PrimaryScreenHeight),
columns = (int)(SystemParameters.PrimaryScreenWidth),
alternate = yOffset == 5 ? yOffset : 1,
j = 0;
//Draw the horizontal lines
Point x = new Point(0, 0.5);
Point y = new Point(SystemParameters.PrimaryScreenWidth, 0.5);
for (int i = 0; i <= rows; i++, j++)
{
dct.DrawLine(j % alternate == 0 ? lightPen : darkPen, x, y);
x.Offset(0, yOffset);
y.Offset(0, yOffset);
}
j = 0;
Finally use Image and RenderTargetBitmap to save the line for the Grid: