Building a workflow Designer using Silverlight (17)-Persisting data to database-designing webservices interfaces
In the beginning, the program added a small function, is to the container to increase the function of the grid line, so that the container looks like the following look
Of course, there are two ways to achieve, one is to use the background image, but the consistent primary colors of this article is to use less pictures, the use of Silverlight's drawing function to achieve, these grids can use the line object in XAML to implement. For this we need to dynamically set a canvas, and then add these dynamically generated line objects to the canvas, and finally add canvas to the container, which is simpler, but in the program, you need to consider rollback, zindex effect. The following code describes the ability to dynamically increase grid lines.
Code
GridLinesContainer.Children.Clear ();
SolidColorBrush brush = new SolidColorBrush ();
Brush. Color = Color.FromArgb (255, 160, 160, 160);
Brush. Color = Color.FromArgb (255, 255, 255, 255);
Double thickness = 0.3;
Double top = 0;
Double left = 0;
Double width = cnsdesignercontainer.width;
Double height = cnsdesignercontainer.height;
Double steplength = 40;
Double x, y;
x = left + steplength;
y = top;
while (x < width + left)
{
Line line = new Line ();
Line. X1 = x;
Line. Y1 = y;
Line. X2 = x;
Line. Y2 = y + height;
Line. Stroke = brush;
Line. StrokeThickness = thickness;
Line. Stretch = Stretch.fil;
GRIDLINESCONTAINER.CHILDREN.ADD (line);
x + + steplength;
}
x = left;
y = top + steplength;
while (Y < height + top)
{
Line line = new Line ();
Line. X1 = x;
Line. Y1 = y;
Line. X2 = x + width;
Line. Y2 = y;
Line. Stroke = brush;
Line. Stretch = Stretch.fil;
Line. StrokeThickness = thickness;
GRIDLINESCONTAINER.CHILDREN.ADD (line);
Y + + steplength;
}