Welcome

首页 / 软件开发 / Silverlight / 使用silverlight构建一个工作流设计器(十七)-持久化数据到数据库

使用silverlight构建一个工作流设计器(十七)-持久化数据到数据库2009-11-20 博客园 chegan使用silverlight构建一个工作流设计器(十七)-持久化数据到数据库—设计webservices接口

在开始之间,先说下程序增加的一个小功能,就是给容器增加网格线的功能,使得容器看上去类似下面的样子

当然可以有两种方法来实现,一种就是使用背景图片,但本文一贯的原色就是少用图片,多用silverlight的画图功能来实现,这些网格都可以使用xaml中的Line对象来实现。为此我们需要动态设定一个Canvas,然后把这些动态生成的Line对象添加到Canvas中,最后再把Canvas添加到容器里面,这里讲的比较简单,但是在程序中,还需要考虑回滚,Zindex的影响。下面的代码描述了动态增加网格线的功能。

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;
}