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