在我的wpf应用程序中,我想要更新画布上的一条线(改变起点和终点坐标)并预览更改。问题在于我添加了这条线,但只能看到初始和最终状态。
有没有办法使线条/画布实时更新自身?我想看到线条如何改变长度/位置。
例如,我收到一系列线段的起始/结束对列表。如果我循环该列表并使用来自对值的坐标更新线段的坐标,则无法看到中间状态。
我尝试将线条和画布的可见性设置为可见以强制它们更新,但不起作用。如果我只是添加新的线条,我看不到它们如何添加,只能看到最终结果。
在下面的代码中,每当我有新点时,都会从循环中调用DrawLine方法。
有什么建议吗?
有没有办法使线条/画布实时更新自身?我想看到线条如何改变长度/位置。
例如,我收到一系列线段的起始/结束对列表。如果我循环该列表并使用来自对值的坐标更新线段的坐标,则无法看到中间状态。
我尝试将线条和画布的可见性设置为可见以强制它们更新,但不起作用。如果我只是添加新的线条,我看不到它们如何添加,只能看到最终结果。
在下面的代码中,每当我有新点时,都会从循环中调用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();
}