1
在我的wpf应用程序中,我想更新画布上的一行(更改开始,终点坐标)并预览更改。问题是,我添加了该行,但我只能看到初始状态和最终状态。如何更新WPF画布真的很快?
有没有办法让线条/画布实时更新?我想看看这条线是如何改变长度/位置的。
例如,我收到该行的开始/结束对列表。如果我循环列表并更新线对的坐标值,我不能看到中间状态。
我试图将行和画布的可见性设置为可见,强制它们更新但不起作用。如果我只是添加新行,我不能看到它们是如何添加的,只是最后一步。
在下面的代码中,每次我有新的点时,循环都会调用DrawLine方法。
有什么建议吗?
public void DrawLine(List<Library2d.Point> points)
{
PathFigure myPathFigure = new PathFigure();
myPathFigure.StartPoint = new System.Windows.Point(points.ElementAt(0).X, points.ElementAt(0).Y);
LineSegment myLineSegment = new LineSegment();
myLineSegment.Point = new System.Windows.Point(points.ElementAt(1).X, points.ElementAt(1).Y);
PathSegmentCollection myPathSegmentCollection = new PathSegmentCollection();
myPathSegmentCollection.Add(myLineSegment);
myPathFigure.Segments = myPathSegmentCollection;
PathFigureCollection myPathFigureCollection = new PathFigureCollection();
myPathFigureCollection.Add(myPathFigure);
PathGeometry myPathGeometry = new PathGeometry();
myPathGeometry.Figures = myPathFigureCollection;
if (myPath == null)
{
myPath = new Path();
myPath.Stroke = Brushes.ForestGreen;
myPath.StrokeThickness = 1;
canvas.Children.Add(myPath);
}
myPath.Data = myPathGeometry;
myPath.Visibility = Visibility.Visible;
myPath.InvalidateMeasure();
canvas.Visibility = Visibility.Visible;
canvas.InvalidateMeasure();
}