我在画布元素上创建了一个坐标系。我为每一个得到的价值绘制一个红点,并将其与旧的连接起来。WPF坐标系统更新
在这里看到:
我越来越每秒约10个值。
1值= 1个像素
红线代表的值,我发现了一个恒定的值只是用于测试。
我的目标是在绘图达到坐标系末端时更新绘图。 我想把我的图画推向左边并绘制下一个点。
我的目标是:
- 我不想失去点在我的图,因为后来我想放大和缩小
- 我不希望我的系统慢下来尽可能少...
这是我的代码,但不知道如何可以更新在结尾部分的图....
static double xOld = 32;
static double yOld = 580;
static double t = 32;
System.Windows.Shapes.Path path;
static GeometryGroup lineGroupDrw1 = new GeometryGroup();
....
public void drawPoly(double value)
{
//increase point position
t++;
//generate 2 point for the connection
Point pOne = new Point(xOld, yOld);
Point pTwo = new Point(t, value);
//connect old point with new
GeometryGroup lineGroup = new GeometryGroup();
LineGeometry connectorGeometry = new LineGeometry();
connectorGeometry.StartPoint = pOne;
connectorGeometry.EndPoint = pTwo;
lineGroup.Children.Add(connectorGeometry);
path = new System.Windows.Shapes.Path();
path.Data = lineGroup;
path.StrokeThickness = 1;
path.Stroke = path.Fill = Brushes.Red;
//fill the static linegroup with a new point
lineGroupDrw1.Children.Add(connectorGeometry);
if (coordinateSystem.Width > t)
{
// draw graph
coordinateSystem.Children.Add(path);
}
else
{
//To do : update drawing
updateDrawingEnd();
}
//refresh values
xOld = t;
yOld = value;
}
....
public void updateDrawingEnd()
{
path = new System.Windows.Shapes.Path();
path.Data = lineGroupDrw1;
path.StrokeThickness = 1;
path.Stroke = path.Fill = Brushes.Yellow;
coordinateSystem.Children.Add(path);
t = 145;
}
发布您的完整代码和XAML。 – 2013-05-14 14:16:43